Comments (12)
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.
Thanks for this. I definitely did not test this with non US keyboard layouts. I'll have to take a look later.
from mousetrap.
I can only concur that it's the same issue on a Swedish keyboard.
from mousetrap.
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.
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 /
.)
from mousetrap.
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.
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.
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.
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.
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.
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.
Works perfectly on Turkish layout. Thanks!
from mousetrap.
Related Issues (20)
- Can Mousetrap detect Windows key for the purposes of intercepting Window switching in Electron app?
- Not a question, but is nyan cat supposed to be here?
- Reactive form setValue not correctly working after event generated by Mousetrap
- Adding mousetrap to textarea class does not work, Mousetrap.prototype.stopCallback does work HOT 1
- bind('1',()=>{console.log('1')}) HOT 1
- typescript support and npm package? HOT 1
- Typing 25 acts like if you've typed 2 HOT 3
- Command+- not captured on Firefox (but does on all other browsers tested) HOT 1
- ctrl+, not work
- List of mapped keys
- shift-ctrl-alt-4 activates ctrl-alt-4
- escape key does not bind on Safari HOT 1
- Needs ESM export
- Needs ESM export
- ctrl+tab doesn't fire HOT 1
- Use of navigator.platform invokes Chrome issue
- ev.which is readonly and hence should not be assigned during normalization.
- Shortcuts that are a combination (f+i) are saved under the second key - if there is a collision in that second key, the callbacks can misfire HOT 1
- Are there any alternatives to mousetrap? HOT 7
- Unbind or reset fails to remove hot key HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mousetrap.