2006-06Jun-02
KeyPress Event
Qualifier keys such as ALT, CTRL and SHIFT are prioritized in this order. When the user presses a
combination of these three keys, the
highest qualifier determines the key code. If, for instance, the ALT key is
pressed with SHIFT, the key code is the same as if you pressed the key and just
ALT. If the user instead presses SHIFT and CTRL, the key code switches to the
CTRL combination. Only when the SHIFT key is pressed, you would end up with the
SHIFT key code. The following table clarifies this for the U key:
nKeyCode nShiftAltCtrl
U 117 0
Shift+U 85 1
Ctrl+U 21 2
Alt+U 22 4
Shift+Ctrl+U 21 3
Shift+Alt+U 22 5
Ctrl+Alt+U 22 6
Shift+Alt+Ctrl+U 22 7 (works only intermittently on my laptop)
The exception from the rule above is the SHIFT+ALT combination on keyboards that support an
ALTGR key. SHIFT+ALT+Key and ALTGR+Key
trigger the KeyPress event with nShiftAltCtrl=0 and the regular key code.
With ALT combinations, the key code
corresponds to the
physical location on a US keyboard.
Pressing the key between T and U on a German keyboard results in a key code of
122, whereas it returns 121 with a US keyboard layout. However, with the ALT
key, the key code is 21 in both cases.
This is the same side
effect that occurs with ON KEY LABEL and with certain key combination to control
child windows such as ALT+hypen (ALT+-) on a US keyboard which requires a German
user to press ALT+ß.
Some special keys fire the KeyPress event, as well:
| |
nKeyCode |
nShiftAltCtrl |
| Caps
Lock+Shift+Alt |
58 |
6 (not reliable) |
| |
57 |
5 (not reliable) |
| Ctrl+Win+Alt |
91 |
7 |
| Shift+Alt+0 |
11 |
5 |
Some codes are identical. However, this doesn't necessarily apply to all qualifier key combinations.
| |
nKeyCode |
nShiftAltCtrl |
| Ctrl++ / Ctrl+Pos1 |
29 |
2 |
| Ctrl+H / Ctrl+Del |
127 |
2 |
| Ctrl+W / Ctrl+End |
23 |
2 |
| Ctrl+Left Arrow / Ctrl+Z |
26 |
2 |
| Ctrl+Right Arrow / Ctrl+B |
2 |
2 |
| Alt+0 / Alt+R |
19 |
4 |
| Shift+Alt+0 |
19 |
5 |
| Ctrl+J / Ctrl+Enter |
10 |
3 |
| Shift+Ctrl+J |
10 |
3 |
| Shift+Z / Shift+F7 |
90 |
1 |
| Shift+T / Shift+F1 |
84 |
1 |
| Shift+U / Shift+F2 |
85 |
1 |
| Shift+W / Shift+F4 |
87 |
1 |
| Shift+Y / Shift+F6 |
89 |
1 |
| Shift+X / Shift+F5 |
88 |
1 |
| Shift+V / Shift+F3 |
86 |
1 |
The following combination do not work in conjunction with Ctrl or Ctrl+Shift. The first label is
the corresponding key on a German keyboard, the second value on a US keyboard
| German |
US |
| ^ |
' |
| 1 |
1 |
| 2 |
2 |
| 3 |
3 |
| 4 |
4 |
| 5 |
5 |
| 6 |
6 |
| 7 |
7 |
| 8 |
8 |
| 9 |
9 |
| ß |
- |
| ' |
= |
| Ö |
; |
| Ä |
' |
| , |
, |
| . |
. |
| - |
/ |
SHIFT+F10 is the context menu key and therefore returns nKeyCode=93 and nShiftAltCtrl=1.
With CapsLock, the key codes are inverted.