The lParam parameter of a keystroke message contains additional information about the keystroke that generated the message. This information includes the repeat count, the scan code, the extended-key flag, the context code, the previous key-state flag, and the transition-state flag. The following illustration shows the locations of these flags and values in the lParam parameter.
An application can use the following values to manipulate the keystroke flags.
Value | Meaning |
---|---|
KF_ALTDOWN | Manipulates the alt key flag, which indicated if the alt key is pressed. |
KF_DLGMODE | Manipulates the dialog mode flag, which indicates whether a dialog box is active. |
KF_EXTENDED | Manipulates the extended key flag. |
KF_MENUMODE | Manipulates the menu mode flag, which indicates whether a menu is active. |
KF_REPEAT | Manipulates the repeat count. |
KF_UP | Manipulates the transition state flag. |
You can check the repeat count to determine whether a keystroke message represents more than one keystroke. The system increments the count when the keyboard generates WM_KEYDOWN or WM_SYSKEYDOWN messages faster than an application can process them. This often occurs when the user holds down a key long enough to start the keyboard's automatic repeat feature. Instead of filling the system message queue with the resulting key-down messages, the system combines the messages into a single key down message and increments the repeat count. Releasing a key cannot start the automatic repeat feature, so the repeat count for WM_KEYUP and WM_SYSKEYUP messages is always set to 1.
The scan code is the value that the keyboard hardware generates when the user presses a key. It is a device-dependent value that identifies the key pressed, as opposed to the character represented by the key. An application typically ignores scan codes. Instead, it uses the device-independent virtual-key codes to interpret keystroke messages.
The extended-key flag indicates whether the keystroke message originated from one of the additional keys on the enhanced keyboard. The extended keys consist of the alt and ctrl keys on the right-hand side of the keyboard; the ins, del, home, end, page up, page down and arrow keys in the clusters to the left of the numeric keypad; the num lock key; the break (ctrl+pause) key; the print scrn key; and the divide (/) and enter keys in the numeric keypad. The extended-key flag is set if the key is an extended key.
The context code indicates whether the alt key was down when the keystroke message was generated. The code is 1 if the alt key was down and 0 if it was up.
The previous key-state flag indicates whether the key that generated the keystroke message was previously up or down. It is 1 if the key was previously down and 0 if the key was previously up. You can use this flag to identify keystroke messages generated by the keyboard's automatic repeat feature. This flag is set to 1 for WM_KEYDOWN and WM_SYSKEYDOWN keystroke messages generated by the automatic repeat feature. It is always set to 0 for WM_KEYUP and WM_SYSKEYUP messages.
The transition-state flag indicates whether pressing a key or releasing a key generated the keystroke message. This flag is always set to 0 for WM_KEYDOWN and WM_SYSKEYDOWN messages; it is always set to 1 for WM_KEYUP and WM_SYSKEYUP messages.