adopted-ember-addons/ember-keyboard

event.key and code confusion

oskarrough opened this issue · 4 comments

Hi, I'm trying to create a keyboard shortcut for the / (Slash) key.

With US language settings on an US keyboard, keyDown('Slash') is all that is needed.
But if I change to, for example, German language on the same keyboard, it doesn't.

This is, as I understand, because of the difference between event.key and event.code.
Where one represents the physical key's location while the other is the symbol itself?

  • slash key with us language: key=/, code=Slash and keyCode=191
  • same key with german language: key=- code=Slash and keyCode=189
  • slash key on german keyboard =key=/, code=Digit7 and keyCode=55

I read #88 and #34 and see you've already been down the rabbit hole. But I couldn't quite understand how it's supposed to work. So the question is, how do you bind to a certain symbol so it works across languages — and not the key's location on the keyboard?

Thanks a lot for a great project!

@oskarrough Great question. This addon is currently based on code. As far as I know, there is no easy way to bind to the key of an event. I would be open to exploring an API to support declaring shortcuts based on key if anyone wants to tackle this.

We're going to try to resolve this via #135

Should now be resolved by #135, which includes tests for the specific cases cited in this issue.

Woo! Thank you