Register System hotkeys with RegisterHotKey

Source: Internet
Author: User
RegisterHotKey

Function function: This function defines a system-wide hot key.

Function prototype: BOOL RegisterHotKey (HWND hWnd, intid, UINT fsModifiers, UINT vk );

Parameters:

HWnd: The Window handle for receiving the WM_HOTKEY message generated by the hotkey. If this parameter is NULL, The WM_HOTKEY message passed to the calling thread must be processed in the message loop.

Id: The identifier that defines the hotkey. Other hotkeys in the call thread cannot use the same identifier. The application must define a value in the 0X0000-0xBFFF range. A shared dynamic link library (DLL) must define a value in the 0xC000-0xFFFF range returned by the value of the globalglobaladdatom function ). To avoid conflicts with hotkeys defined by other dynamic link libraries, a DLL must use the GlobalAddAtom function to obtain the identifier of the hotkey.

FsModifoers: defines the key that must be pressed together with the key defined by the reset rtkey parameter to generate the WM_HOTKEY message. This parameter can be a combination of the following values:

MOD_ALT: you can press any Alt key. MOD_CONTROL: press any Ctrl key.

MOD_SHIFT: you can press any Shift key.

MOD_WIN: you can press any Windows button. These keys can be recorded in Microsoft Windows logs.

Vk: Specifies the virtual key code of the hotkey.

Return Value: if the function is successfully called, a non-O value is returned. If the function call fails, the return value is 0. To obtain more error information, call the GetLastError function.

Note: When a key is terminated, the system searches for the matched key in all hotkeys. Once a matching Hot Key is found, the system will pass the WM_HOTKEY message to the Message Queue of the thread that registers the hot key. The message is sent to the queue header, so it will be removed in the next message loop. This function cannot associate hotkeys with windows created by other threads.

The RegisterHotKey function fails to be called if the specified key has been defined by other hotkeys.

If the windows marked by the hWnd parameter have registered a hotkey with the same identifier as the id Parameter definition, the new values of the fsModifiers and vk parameters will replace the values previously defined by these parameters.

 
  1. LRESULT OnHotKey (WPARAM wParam, LPARAM lParam); // hotkey Message Processing Function
  2. ON_MESSAGE (WM_HOTKEY, & OnHotKey) // registers the message function
  3. RegisterHotKey (this-> m_hWnd, 0, MOD_CONTROL, 0x57); // this-> m_hWnd current window handle, MOD_CONTROL is CTRL, 0x57 is W key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.