#626 – Key Up/Down Sequence When Using CTRL Key
August 16, 2012 Leave a comment
When you use the Ctrl-key in combination with another key, e.g. pressing Ctrl-G, the control that has focus will receive KeyUp and KeyDown events for both the Ctrl key and the main key that you are pressing.
For example, if a TextBox control has focus and I press Ctrl-G (which doesn’t normally do anything in a TextBox) and I use the Ctrl key on the left side of the keyboard, I’ll see the following events for the TextBox, in the sequence listed.
- PreviewKeyDown, key = LeftCtrl
- KeyDown, key = LeftCtrl
- PreviewKeyDown, key = G
- KeyDown, key = G
- PreviewKeyUp, key = G
- KeyUp, key = G
- PreviewKeyUp, key = LeftCtrl
- KeyUp, key = LeftCtrl
In this case, you can see that my sequence in pressing/releasing the keys was:
- Press and hold left Ctrl key
- Press G key
- Release G key
- Release Ctrl key