is-hotkey
is-hotkey copied to clipboard
Can't match certain hotkeys on Mac
First of all, thank you for this convenient library!
I faced an issue with one hotkey on Mac, which I believe is somewhat similar to https://github.com/ianstormtaylor/is-hotkey/issues/1
The hotkey is defined as mod+alt+n
. It's not possible to match it on Mac with isHotkey
/isKeyHotkey
, because in the first case the which
property has the value of 192
(while the expected value is 78
), and in the second, the key
prop has the value of "Dead"
(isKeyHotkey
expects "k"
).
Here's the keydown event object for cmd+opt+n
:
altKey: true
charCode: 0
code: "KeyN"
composed: true
ctrlKey: false
key: "Dead"
keyCode: 192
metaKey: true
repeat: false
returnValue: true
shiftKey: false
which: 192
What would be the best way to fix this? Is checking the code
prop safe in case key
is "Dead"
?
Hmm interesting, do you know why that specific key results in a dead key? Maybe it needs to support which
, key
and code
? All of which are separate.
Unfortunately no. According to multiple resources, 192 is the code of backtick/grave accent ([1], [2]). opt+n
inserts ˜
and results in a dead key as well (to make things even more confusing, which
is 78
in this case)
This seems to depend on the layout - the issue is reproducible with British
, U.S.
, and German
but everything works as expected with Unicode Hex input
, Arabic - QWERTY
, and Russian - PC
.
I'll investigate this further tomorrow.
Hi there! I'm coming across the same issue formod+alt+n
, is there any suggestion for a workaround or what a proposed fix might entail @going-confetti? Thank you for this helpful library @ianstormtaylor!
Hi @Jacfem, I used a workaround for this specific hotkey.
For mod+alt+n
, instead of
if (isHotkey('mod+alt+n', e)) {
// ...
}
you could use something like this
if (e.metaKey && e.altKey && e.code === 'KeyN') {
// ...
}
@ianstormtaylor looks like checking the code
property of the event object could indeed work for issues like this. Currently,isCodeHotkey
is an alias for isHotkey
, would you be open for a PR that will either
- introduce a breaking change by turning it into a function that checks
code
instead ofwhich
/key
- add a new exported function that will be doing that instead
?
Thank you for the quick reply @going-confetti! That workaround seems to be working from a quick test, I really appreciate it.
Thanks @going-confetti, I'd be down a PR there.
Is it possible that just checking code
instead of which
for the default case? Or do we need which
sometimes and code
sometimes? If possible to keep it simplest that would be great.