adopted-ember-addons/ember-keyboard

Windows `keydown` with `shift` triggers with the uppercase key

swastik opened this issue · 4 comments

Hey there! Thanks for this great addon! 😄

I'm trying to add a keyboard shortcut in my app, something like cmd+shift+g. I'm registering it like {{on-key "cmd+shift+g" this.doSomething}}. It seems to work on Mac, however on Windows the shortcut is never triggered.

Looking at javascript.info on Mac, the keydown event is triggered with lowercase g:

ic 2022-04-12 at 21 18 57@2x

On Windows, keydown is triggered with uppercase G:

ic 2022-04-12 at 21 20 00@2x

Anything with shift seems to trigger with its uppercase variation. I'm assuming the shortcut isn't triggered because of that. I cannot use code because that doesn't seem to work with different keyboard layouts.


Questions:

  1. Is this known? Are there any known workarounds for this?
  2. Is this something that should be handled within the library? For now, registering all variations of the shortcut (i.e. both cmd+shift+g and cmd+shift+G) seems to work, but it also feels like I'm doing the wrong thing!

I'd appreciate any thoughts—thank you!

It seems like these lines are trying to do something similar, but it probably doesn't get to it because shift isn't the only modifier in my shortcut. 🤔

i hit this as well with ctrl+shift+f not firing while ctrl+shift+F does, on MacOS w/FireFox 108

@tehhowch @swastik Thanks for your bug report and the follow up. This definitely sounds like something we should improve. This test file is a bit complex but it would be the one to try to add a a failing test to: https://github.com/adopted-ember-addons/ember-keyboard/blob/master/test-app/tests/unit/utils/is-key-test.js

If anyone wants to try their hand at a PR, I am happy to review and offer guidance. Feel free to hit me up on Discord if you'd like to discuss as you dive in.

I'm having similar issues with cross-platform and keyboard layout compatibilty.
There doesn't seem to be any way to register at alt+ keypress which is compatible with Windows and Mac and supports more than the QWERTY keyboard layout.

Attempt to register ctrl+alt+e
On mac it needs to be registered as ctrl+alt+´

Attempt instead to use ctrl+alt+KeyE
in a different keyboard layout, e.g. Dvorak or Colemak it comes through as KeyE or KeyK because it's using the underlying QWERTY key for whatever reason rather than the layout.

image

The only reliable way seems to be the ascii code which.