KeyboardProc

3.1

  LRESULT CALLBACK KeyboardProc(code, wParam, lParam)    
  int code; /* process-message flag, */  
  WPARAM wParam; /* virtual-key code, */  
  LPARAM lParam; /* keyboard-message information */

The KeyboardProc function is a library-defined callback function that the system calls whenever the application calls the GetMessage or PeekMessage function and there is a WM_KEYUP or WM_KEYDOWN keyboard message to process.

Parameters

code

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, extended key, previous key state, context code, and key-transition state, as shown in the following table. (Bit 0 is the low-order bit):

Bit Description

0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if it is an extended key; otherwise, it is 0.
25–26 Not used.
27–28 Used internally by Windows.
29 Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the key-transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.

Return Value

The callback function should return 0 if the message should be processed by the system; it should return 1 if the message should be discarded.

Comments

This callback function must be in a dynamic-link library.

An application must install the callback function by specifying the WH_KEYBOARD filter type and the procedure-instance address of the callback function in a call to the SetWindowsHookEx function.

KeyboardProc is a placeholder for the library-defined function name. The actual name must be exported by including it in an EXPORTS statement in the library's module-definition file.

See Also

CallNextHookEx, GetMessage, PeekMessage, SetWindowsHookEx