36.1.7 Hot Key Support

Windows provides a set of functions that you can use to define “hot keys” for your application. A hot key is a key combination that generates a WM_HOTKEY message. The system places a WM_HOTKEY message at the top of a thread's message queue, bypassing any existing messages in the queue. You can use a hot key to obtain high-priority keyboard input from the user. For example, you could define a hot key consisting of the CTRL+C keys to allow the user to cancel a lengthy operation.

You define a hot key by calling the RegisterHotKey function, specifying the combination of keys that generate the WM_HOTKEY message, the handle of the window to receive the message, and the identifier of the hot key. When the user presses the hot key, a WM_HOTKEY message is placed in the message queue of the thread that created the specified window. The wParam parameter of the message contains the identifier of the hot key. You can define multiple hot keys for a thread, but each hot key in the thread must have a unique identifier. You should destroy a hot key by using the UnregisterHotKey function before your application terminates.