Author: Igor Siticov
How to find difference between the two ENTER keys?
An application may find it useful to differentiate between the user pressing the
ENTER key on the standard keyboard and the ENTER key on the numeric keypad. Either
action creates a WM_KEYDOWN message and a WM_KEYUP message with wParam set to the
virtual key code VK_RETURN. When the application passes these messages to
TranslateMessage, the application receives a WM_CHAR message with wParam set to the
corresponding ASCII code 13.
To differentiate between the two ENTER keys, test bit 24 of lParam sent with the
three messages listed above. Bit 24 is set to 1 if the key is an extended key;
otherwise, bit 24 is set to 0 (zero).
Because the keys in the numeric keypad (along with the function keys) are extended
keys, pressing ENTER on the numeric keypad results in bit 24 of lParam being set,
while pressing the ENTER key on the standard keyboard results in bit 24 clear.
The following code sample demonstrates differentiating between these two ENTER
1 2 procedure TForm1.WMKeyDown(varmessage: TWMKeyDown);
3 begin4 inherited;
5 casemessage.CharCode of6 VK_RETURN:
7 begin// ENTER pressed8 if (message.KeyData and $1000000 <> 0) then// Test bit 24 of lParam9 begin10 // ENTER on numeric keypad11 12 end13 else14 begin15 // ENTER on the standard keyboard16 17 end;