RegisterHotKey

  BOOL RegisterHotKey(hwnd, idHotKey, fuModifiers, uVirtKey)    
  HWND hwnd; /* window to receive hot-key notification */
  int idHotKey; /* identifier of hot key */
  UINT fuModifiers; /* key-modifier flags */
  UINT uVirtKey; /* virtual-key code */

The RegisterHotKey function defines a hot key for the current thread.

Parameters

hwnd

Identifies the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to message queue of the calling thread and must be processed in the message loop.

idHotKey

Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot key identifier.

fuModifiers

Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fuModifiers parameter can be a combination of the following values:

Value Meaning

HOTKEYF_SHIFT  
  Either SHIFT key must be held down.
HOTKEYF_CONTROL  
  Either CTRL key must be held down.
HOTKEYF_ALT  
  Either ALT key must be held down.

uVirtKey

Specifies the virtual-key code of the hot key.

Return Value

The return value is TRUE if the function is successful or FALSE if an error occurs.

Comments

When a key is pressed, the system looks for a match against all thread hot keys. When a match is found, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.

This function cannot associate a hot key with a window created by another thread.

This function fails if the keystrokes specified for the hot key have already been registered by another hot key.

If the window identified by the hwnd parameter already registered a hot key with the same identifier as that specified by the idHotKey parameter, the new values for the fuModifiers and uVirtKey parameters replace the previously specified values for these parameters.

See Also

UnregisterHotKey, WM_HOTKEY