Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows keydown with shift triggers with the uppercase key #621

Open
swastik opened this issue Apr 12, 2022 · 4 comments
Open

Windows keydown with shift triggers with the uppercase key #621

swastik opened this issue Apr 12, 2022 · 4 comments

Comments

@swastik
Copy link

swastik commented Apr 12, 2022

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!

@swastik
Copy link
Author

swastik commented Apr 12, 2022

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. 🤔

@tehhowch
Copy link

tehhowch commented Jan 19, 2023

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

@lukemelia
Copy link
Collaborator

@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.

@artsyca
Copy link

artsyca commented Jan 26, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants