How to capture CTRL + CTRL key presses in my Win32 application?
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.
精彩评论