iohook
iohook copied to clipboard
Shortcuts fired with extra keys present
If you press all the keys of a registered shortcuts while another additional keys are pressed, the shortcut is still triggered.
Expected Behavior
Register two shortcuts:
ioHook.registerShortcut([0x0002], doThis); // Register shortcut for pressing the '1' key
ioHook.registerShortcut([0x0002, 0x002A], doThat); // Register shortcut for pressing Shift+1
Now if you press Shift+1, only doThat
should be invoked.
Current Behavior
At the moment if you do the above and press Shift+1, both doThis
and doThat
are invoked.
Possible Solution
When checking for a shortcut, also ensure that no other keys are pressed before deeming it activated. Possibly add an optional flag to shortcut registration which specifies if it should ignore extra keys or not.
Context
I have an application with user-configurable keyboard shortcuts. Users would expect the above example to work as I described, and the only way for me to make that happen at the moment with ioHook is to forgo shortcut registration and implement shortcut recognition on my own with the key-up and key-down events. My goal here is simply what is naturally considered a keyboard shortcut. When you press Alt+Enter, it shouldn't activate a shortcut for Alt or for Enter separately, but only for the combination of both.
Your Environment
- Version used: 0.6.6
- Environment name and version: Node.js 14.15.4
- Operating System: Windows 10 on desktop
As far as general key capture goes, this is the correct behavior. Mod keys don't alter keycodes, they modify behavior. I do believe though that this is a missing feature that should be implemented, namely providing a way to distinguish modded keydown and keyup events from unmodded ones.