Much of an application's user input comes from the keyboard. Windows sends keyboard input to an application when the user presses or releases a key. Windows generates keyboard-input messages in response to the following keyboard events:
Message | Event |
WM_KEYDOWN | User presses a key. |
WM_KEYUP | User releases a key. |
WM_SYSKEYDOWN | User presses a system key. |
WM_SYSKEYUP | User releases a system key. |
The wParam parameter of a keyboard-input message specifies the virtual-key code of the key the user pressed. A virtual-key code is a device-independent value for a specific keyboard key. Windows uses virtual-key codes so that it can provide consistent keyboard input no matter what computer your application is running on.
The lParam parameter contains the keyboard's scan code for the key, as well as additional information about the keyboard, such as the state of the SHIFT key and whether the current key was previously up or down.
Windows generates two system-key messages, WM_SYSKEYUP and WM_SYSKEYDOWN. System keys are special keys, such as the ALT and F10 keys, that belong to the Windows user interface and cannot be used by an application in any other way.
An application receives keyboard-input messages only when it has the input focus. The input focus is what your application receives when it becomes the active application—that is, when the user has selected the application's window. You can also use the SetFocus function to explicitly set the input focus for a given window, and the GetFocus function to determine which window has the focus.