#629 – Some Controls May Swallow Keypress Events

If you are handling KeyUp and/or KeyDown events for a control, you’ll notice that certain keys may be “swallowed” by a particular control.  In other words, you might not get all of the keypress events.

A control may intercept a particular event and mark it as handled if it interprets the keypress and uses it within the control.

For example, a TextBox control will “swallow” the KeyDown event for the Backspace key, since this key is used to delete characters in the control.

In the example below, I press the ‘a’ key and see all four (PreviewKeyDown, KeyDown, PreviewKeyUp, KeyUp) keypress events.  However, when I press Backspace, I see only three events–the TextBox intercepts the KeyDown event, erases a character, and marks the event as handled.


About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #629 – Some Controls May Swallow Keypress Events

  1. Pingback: Dew Drop – August 22, 2012 (#1,386) | Alvin Ashcraft's Morning Dew

  2. Pingback: #637 – Block Repeating Keys by Setting Handled to true « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: