Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function defines a system-wide hot key.

Syntax

BOOL RegisterHotKey( 
  HWND 
hWnd, 
  int 
id, 
  UINT 
fsModifiers, 
  UINT 
vk 
);

Parameters

hWnd

[in] Handle to the window that will receive WM_HOTKEYmessages generated by the hot key. The value of this parameter should not be NULL.

id

[in] 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.

fsModifiers

[in] Specifies keys that must be pressed in combination with the key specified by the nVirtKeyparameter in order to generate a WM_HOTKEY message. The fsModifiersparameter can be a combination of the following values.

Value Description

MOD_ALT

Either ALT key must be held down.

MOD_CONTROL

Either CTRL key must be held down.

MOD_KEYUP

Both key up events and key down events generate a WM_HOTKEY message.

MOD_SHIFT

Either SHIFT key must be held down.

MOD_WIN

Either WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo.

vk

[in] Specifies the virtual-key code of the hot key.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, 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.

RegisterHotKeycan be used to register hot keys across threads.

RegisterHotKeyfails if the keystrokes specified for the hot key have already been registered by another hot key.

If the window identified by the hWndparameter already registered a hot key with the same identifier as that specified by the idparameter, the new values for the fsModifiersand vkparameters replace the previously specified values for these parameters.

Requirements

Header winuser.h
Library Hotkey.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also