Coder Social home page Coder Social logo

Comments (12)

skfd avatar skfd commented on May 20, 2024 6

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

from mousetrap.

ccampbell avatar ccampbell commented on May 20, 2024

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

from mousetrap.

robnyman avatar robnyman commented on May 20, 2024

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

from mousetrap.

ccampbell avatar ccampbell commented on May 20, 2024

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.

from mousetrap.

jamesarosen avatar jamesarosen commented on May 20, 2024

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

from mousetrap.

FredrikWendt avatar FredrikWendt commented on May 20, 2024

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

from mousetrap.

ccampbell avatar ccampbell commented on May 20, 2024

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.

from mousetrap.

FredrikWendt avatar FredrikWendt commented on May 20, 2024

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. :-)

from mousetrap.

jamesarosen avatar jamesarosen commented on May 20, 2024

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.

from mousetrap.

jamesarosen avatar jamesarosen commented on May 20, 2024

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.

from mousetrap.

ccampbell avatar ccampbell commented on May 20, 2024

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.

from mousetrap.

frontsideair avatar frontsideair commented on May 20, 2024

Works perfectly on Turkish layout. Thanks!

from mousetrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.