# WPF keyboard input question

**URL:** <https://forum.kirupa.com/t/wpf-keyboard-input-question/226972>\
**Category:** programming\
**Created:** [May 25, 2007, 2:47pm UTC](https://forum.kirupa.com/t/wpf-keyboard-input-question/226972 "2007-05-25T14:47:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kommi](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@Kommi](https://forum.kirupa.com/u/Kommi)\
**Post date:** [May 25, 2007, 2:47pm UTC](https://forum.kirupa.com/t/wpf-keyboard-input-question/226972/1 "2007-05-25T14:47:21Z")

</div>

[FONT=Times New Roman][SIZE=3]Ok I just started developing using Windows Presentation Foundation and have a little problem adding a shortcut key ability to my app. The problem is that I have my main panel throw a KeyDown event everytime a key is pressed. In the code for “keyDown” I then handle a few special conditions (user pressing crtl + a char). [/SIZE][/FONT]  
[FONT=Times New Roman][SIZE=3]I am using the code from a Kirupa article[/SIZE][/FONT]

```auto
 
public void keyDown(object sender, KeyEventArgs e)
{
// Ctrl + B 
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.B))
{
MessageBox.Show("bold");
}
// Ctrl + U 
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.U))
{
MessageBox.Show("underline");
}
// Ctrl + L 
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.L))
{
MessageBox.Show("link");
}
// Ctrl + R 
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.R))
{
MessageBox.Show("random");
} 
}

```

[FONT=Times New Roman][SIZE=3]The problem is that if my cursor is in a TextBox, and I press a crtl+b, it will get handled by the KeyDown and the ‘B’ will get inputed into the TextBox. How can I prevent this behavior. Obviously I do not want the ‘B’ to get typed into the TextBox if one of the special conditions in my keyboardEvents method is met.[/SIZE][/FONT]
