Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 自定义全局热键_C_Winapi_Global_Registerhotkey - Fatal编程技术网

C 自定义全局热键

C 自定义全局热键,c,winapi,global,registerhotkey,C,Winapi,Global,Registerhotkey,我正在尝试为我的应用程序获取用户定义的全局热键。这是我的申请代码 user.rc CONTROL "", IDC_MHOTKEY, HOTKEY_CLASS, WS_TABSTOP, 91, 86, 68, 14 函数.cpp WORD wHotKey = SendDlgItemMessage(hwnd, IDC_MHOTKEY, HKM_GETHOTKEY, 0, 0); GLOBAL_HOTKEY= wHotKey; RegisterHotKey (

我正在尝试为我的应用程序获取用户定义的全局热键。这是我的申请代码

user.rc

CONTROL         "", IDC_MHOTKEY, HOTKEY_CLASS, WS_TABSTOP, 91, 86, 68, 14
函数.cpp

    WORD wHotKey = SendDlgItemMessage(hwnd, IDC_MHOTKEY, HKM_GETHOTKEY, 0, 0);
    GLOBAL_HOTKEY= wHotKey;
    RegisterHotKey ( NULL, TURN_OFF_HOTKEY, HIBYTE(LOWORD(wHotKey)) , wHotKey);
   if ( messages.message == WM_HOTKEY && ( HIWORD ( messages.lParam ) == GLOBAL_HOTKEY) )
                        alert("Coming only for Single Key");
main.cpp

    WORD wHotKey = SendDlgItemMessage(hwnd, IDC_MHOTKEY, HKM_GETHOTKEY, 0, 0);
    GLOBAL_HOTKEY= wHotKey;
    RegisterHotKey ( NULL, TURN_OFF_HOTKEY, HIBYTE(LOWORD(wHotKey)) , wHotKey);
   if ( messages.message == WM_HOTKEY && ( HIWORD ( messages.lParam ) == GLOBAL_HOTKEY) )
                        alert("Coming only for Single Key");

此代码运行良好,仅当用户选择一个键,而当用户选择多个组合键(如CTRL+F8)时,此代码不起作用。

您需要将虚拟键与wHotKey值隔离开来:

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

您需要将虚拟密钥从wHotKey值中隔离出来:

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