When I bind the ? and the / key with javascript
on qwerty keyboard they have the same
keycode (191)
but you have to press shift to do a ?
.
How can I tell which character was pressed on an azerty keyboard (layout shown below), as they're different keys, both require Shift, and I get the same keycode for them in keyup
.:
$(document).keyup(function(event) {
if (event.which === 191) {
action();
}
});
(Original image is "KB France" by Yitscar (English Wikipedia) Michka B (French Wikipedia) Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - see use in the article linked above.)
Use the keypress
event
$(document).keypress(function(event) {
if (event.which === 666) {
action();
}
});
I don't have an azerty
keyboard or whatever, so I don't get the same keycodes, but the keypress event will return other keycodes, you'll have to check them yourself.
FIDDLE
Check if shift is pressed
$(document).keyup(function(event) {
if (event.which === 191 && event.shiftKey) {
action();
}
});
Note that this is keyboard layout dependent and it will be easier if you can use the keypress
event as https://stackoverflow.com/a/24995506/227299 suggested
See http://unixpapa.com/js/key.html for further information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With