我正在尝试为我的应用程序获取用户定义的全局热键。这是我的应用程序代码,
user.rc
CONTROL "", 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");
此代码效果很好,仅当用户选择单个键并且在选择多个键组合时不工作,如CTRL + F8。
答案 0 :(得分:1)
您需要将虚拟密钥与wHotKey值隔离开来:
RegisterHotKey ( NULL,
TURN_OFF_HOTKEY,
HIBYTE(LOWORD(wHotKey)), // Modifiers
LOBYTE(LOWORD(wHotKey)) // Virtual key
);