question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't match certain hotkeys on Mac

See original GitHub issue

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"?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
going-confetticommented, Sep 2, 2022

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

  1. introduce a breaking change by turning it into a function that checks code instead of which/key
  2. add a new exported function that will be doing that instead

?

1reaction
going-confetticommented, Mar 3, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change a conflicting keyboard shortcut on Mac - Apple Support
Click Keyboard Shortcuts on the right. A warning icon appears next to conflicting keyboard shortcuts. Double-click the shortcut, then change it. See Use...
Read more >
Learn the default keyboard shortcuts in InDesign
*After you select a transformation tool, hold down the mouse button, and then hold down Alt (Windows) or Option (Mac OS) and drag....
Read more >
Configure keyboard shortcuts | PyCharm Documentation
To view the keymap configuration, open the Settings/Preferences dialog Ctrl+Alt+S and select Keymap. Keymap settings. PyCharm automatically ...
Read more >
Create a custom keyboard shortcut for Word for Mac
On the Tools menu, select Customize Keyboard. To restore keyboard shortcuts to their original state, select Reset All.
Read more >
Keyboard Shortcuts and Mouse Actions for Simulink Modeling
On a Mac, press control+left. Change selection to rightmost element relative to cursor. End. On a Mac, press control+right. Select ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found