LRESULT CALLBACK KeyboardProc(nCode, wParam, lParam) | |||||
int nCode; | /* hook code | */ | |||
WPARAM wParam; | /* virtual-key code | */ | |||
LPARAM lParam; | /* keyboard-message information | */ |
The KeyboardProc function is an application- or library-defined callback function that the system calls whenever the application calls the GetMessage or PeekMessage function and there is a keyboard message (WM_KEYUP or WM_KEYDOWN) to process.
nCode
Specifies whether the callback function should process the message or call the CallNextHookEx function. If this value is HC_NOREMOVE, the application is using the PeekMessage function with the PM_NOREMOVE option and the message will not be removed from the system queue. If this value is less than zero, the callback function should pass the message to CallNextHookEx without further processing.
wParam
Specifies the virtual-key code of the given key.
lParam
Specifies the repeat count, scan code, key-transition code, previous key state, and context code, as shown in the following list. Bit 1 is the low-order bit:
Bit | Meaning |
0–15 | ||
Repeat count. Indicates the number of times the keystroke is repeated as a result of the user holding down the key. | ||
16–23 | ||
Scan code. This is an OEM-dependent value. | ||
24 | ||
Extended key. This bit is TRUE if the key is an extended key; FALSE if not. | ||
25–26 | ||
Not used. | ||
27–28 | ||
Context code. This code is used internally by the system. | ||
30 | ||
Previous key state. This bit is TRUE if the key was held down before the message was sent; FALSE if the key was up. | ||
31 | ||
Transition state. This bit is TRUE if the key is being released; FALSE if it is being pressed. |
The callback function should return zero if the message should be processed by the system; it should return 1 if the message should be discarded.
An application must install the callback function by specifying the WH_KEYBOARD filter type and address of the callback function in a call to the SetWindowsHookEx function.
KeyboardProc is a placeholder for the application- or library-supplied function name. The actual name must be exported by including it in the EXPORTS statement in a module-definition file.
CallNextHookEx, GetMessage, PeekMessage, SetWindowsHookEx