Search code examples
c++winapihotkeys

Windows API - registering a hotkey with multiple keys combination


So for example I can easily register a hotkey that is a combination of Shift, Alt (Mod keys) and Up arrow:

RegisterHotKey(NULL, TOP, MOD_SHIFT | MOD_ALT, VK_UP);

This works just fine but what I'm after is registering a hotkey with the same keys as above PLUS another normal key like Left arrow, so the combination would be Shift, Alt, Up arrow, Left arrow.

There isn't space in the function for another argument, and I tried doing a bitwise OR for the Up and Left arrow keys like

VK_UP | VK_LEFT

... but it's not working. If anyone encountered this problem before or knows how I proceed please help!


Solution

  • Windows hotkeys don't support multiple (non-modifiers) keys. You cannot bitwise OR multiple VK_* values, only MOD_* values can be combined.

    If you desperately need this feature then you have to use a low-level keyboard hook and track the keys yourself. Hooking affects global system performance and should be avoided if possible.

    If you decide to do this you have to remember that Windows users are not used to pressing hotkeys this way, only menus allow a somewhat similar pattern but you don't have to hold the Alt modifier to make those work. You must also remember to test your hook with StickyKeys and other accessibility features...