开发者

How to capture CTRL + CTRL key presses in my Win32 application?

开发者 https://www.devze.com 2022-12-19 15:57 出处:网络
How would I capture the user pressing Ctrl twice (Ctrl + Ctrl) globally. I want to be able to have my application window hidden and then make it visible when the user invokes it with the CtrlCtrl key

How would I capture the user pressing Ctrl twice (Ctrl + Ctrl) globally. I want to be able to have my application window hidden and then make it visible when the user invokes it with the CtrlCtrl key presses similar to Google Quick Search Box. The user may have focus on a different window. I've looked at RegisterHotKey, but that seems to be for MODIFIERS + character key unless开发者_如何转开发 I'm mistaken.


To create such a hotkey, do this:

ATOM hotkey = GlobalAddAtom("Your hotkey atom name");
if(hotkey) RegisterHotKey(hwnd, hotkey, MOD_CONTROL, VK_CONTROL);
else { ...error... }

And then handle the WM_HOTKEY message:

case WM_HOTKEY:
    if(wParam == hotkey)
    {
       // CTRL pressed!!!
    }
break;

I guess you'll figure out yourself that you need to store whether the CTRL key was pressed before. For example, if it was pressed once in the last 500 ms, and the user presses it again, you have a CTRL+CTRL press.

0

精彩评论

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

关注公众号