开发者

Custom Global Hotkey

开发者 https://www.devze.com 2022-12-25 08:13 出处:网络
I am trying to get the user defined global hot key for my application. Here is my application code, user.rc

I am trying to get the user defined global hot key for my application. Here is my application code,

user.rc

CONTROL         "", 开发者_JS百科IDC_MHOTKEY, HOTKEY_CLASS, WS_TABSTOP, 91, 86, 68, 14

function.cpp

    WORD wHotKey = SendDlgItemMessage(hwnd, IDC_MHOTKEY, HKM_GETHOTKEY, 0, 0);
    GLOBAL_HOTKEY= wHotKey;
    RegisterHotKey ( NULL, TURN_OFF_HOTKEY, HIBYTE(LOWORD(wHotKey)) , wHotKey);

main.cpp

   if ( messages.message == WM_HOTKEY && ( HIWORD ( messages.lParam ) == GLOBAL_HOTKEY) )
                        alert("Coming only for Single Key");

This code works well, Only If the user selects a single key and not working when he selects multiple key combined like CTRL+F8.


You need to isolate the virtual key out of the wHotKey value:

RegisterHotKey ( NULL, 
    TURN_OFF_HOTKEY,  
    HIBYTE(LOWORD(wHotKey)),          // Modifiers
    LOBYTE(LOWORD(wHotKey))           // Virtual key
);
0

精彩评论

暂无评论...
验证码 换一张
取 消