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

International keyboard layouts do not work correctly #2

Closed
frontsideair opened this issue Jul 5, 2012 · 12 comments
Closed

International keyboard layouts do not work correctly #2

frontsideair opened this issue Jul 5, 2012 · 12 comments
Labels

Comments

@frontsideair
Copy link

I tried the examples on demo page using standard Turkish (Q) layout, but some of them didn't work. (Namely, '$' and '*'.)

Now I tried them again and somehow made them work. $ character is typed using AltGr+4 combination, but it didn't work with it or the US variant Shift+4; however it works for AltGr+Shift+4.

On the other hand, asterisk character has a seperate key for itself on Turkish layout. But it also doesn't work. It works by combining Turkish and US layouts and pressing AltGr+Shift+8 --and followed by 'a', of course, for the example to work.

@ccampbell
Copy link
Owner

Thanks for this. I definitely did not test this with non US keyboard layouts. I'll have to take a look later.

@robnyman
Copy link

robnyman commented Jul 5, 2012

I can only concur that it's the same issue on a Swedish keyboard.

@ccampbell
Copy link
Owner

So I think I have an idea about what might fix this. Right now I'm converting to keyCode at binding time, but I think if I store the actual character and then on keypress I use String.fromCharCode(e.keyCode) to compare it might fix this. Will try to experiment with it later.

@jamesarosen
Copy link

The "shift-map" concept doesn't work in an international context. ? is Shift-+ on Danish, Swedish, Norwegian, and Finnish keyboards.

But wait, there's more! If you buy Keybaords From Around the World™ (not actually ™) now, we'll throw in all of the following mappings of ? for free!

  • Shift-' for Italian, Spanish, Latin American, Portuguese (but not Brazilian), Czech, Bosnian, Croatian, Switzerland, and many others
  • France and Belgium have the lovely Shift-, for ?
  • For your Turkish friends, we've got Shift-*
  • No Shift needed in Austria and Germany. There, ? is its own key!

"You're forgetting Poland!" I hear you shout. Nope, we haven't forgotten Poland, where ? is Shift-4. (For those interested, Shift-/ is actually §, except on all the Polish keyboards with no / key, where you type Shift-9 for /.)

And many, many more...

@FredrikWendt
Copy link

I would guess that @jamesarosen is all right (unless you can tell the keyboard layout from JavaScript and the browser, on all OS:es you want to support (apart from the browsers) - as far as I know, I've not seen that in any spec or reference. What I think you can do is make a fairly educated guess on keyboard layout based on locale + OS (for Mac keyboards).
From the docs: "Saying ? is the same thing as saying shift+/" - this part, I think you should separate from the core, or at least allow for pluggability so it can be modified to suite the intended.

Good summaries: http://stackoverflow.com/questions/673905/best-way-to-determine-users-locale-within-browser and http://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference

@ccampbell
Copy link
Owner

Does anyone know if jquery.hotkeys works correctly with international keyboards? I noticed that the way the keys are matched uses String.fromCharCode(keyCode) vs. directly mapping.

I am playing around with it now in a local branch. I hope to have a fix/solution soon.

@FredrikWendt
Copy link

If you want a Swedish keyboard I could send you one. Its layout is very similar to Norwegian, Danish and Finnish, yet rather different from US apart from a-z and space. :-)

@jamesarosen
Copy link

If you're willing to use keypress instead of keyup, you can get a reliable character code of 67 for ?, across all keyboards. Those character codes aren't compatible with String.fromCharCode, though.

@jamesarosen
Copy link

By the way, this problem isn't unique to this project. I've raised the issue on Keymaster and KeyboardJS.

jquery.hotkeys has the same problem, too.

@ccampbell
Copy link
Owner

Hey. Just wanted to comment here to give you all an update. I just pushed out version 1.1, and I think for the most part this ticket should be resolved.

I added support for keypress events which get the character code instead of the keyCode. I tested by changing my mac to a non US keyboard layout and it seems to work in all the tests I conducted. You guys can let me know though.

Basically it is recommended to not specify an event type. For example if you do

Mousetrap.bind('?', _shortcuts);

Then it will use a keypress event.

If you do

Mousetrap.bind('enter', function() {});

Then it will use a keydown event.

@frontsideair
Copy link
Author

Works perfectly on Turkish layout. Thanks!

@skfd
Copy link

skfd commented Apr 28, 2017

Henlo, I think that does not work anymore. Tested on main site by doing Mousetrap.bind('a', ()=>console.log('x'), 'keypress') in console and pressing A button in russian layout.

So, on event contains charCode, keyCode and which all returning 1092 instead of 97 for letter A. There's code: "KeyA" which does proper detection, but it's not supported by Android Chrome...

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

No branches or pull requests

6 participants