How to make a difference between a question mark? and / for sound keyboard

When I bind the keys ?and /using javascripton the qwerty keyboard, they have the same keycode (191), but you have to click shiftto do ?.

How can I specify which symbol has been pressed on azerty keyboard (layout, shown below), as they are for different keys and need shift, and I get to have the same code keyup.:

 $(document).keyup(function(event) {
        if (event.which === 191) {
            action();
        }
    });

Layout

(The original image is “KB France” from Yitscar (English Wikipedia) Michka B (French Wikipedia) License for Creative Commons Attribution-Share Alike 3.0 via Wikipedia - see the use in the article linked above .)

+4
source share
2 answers

Use event keypress

$(document).keypress(function(event) {
    if (event.which === 666) {
        action();
    }
});

I don’t have a keyboard azertyor anything else, so I don’t get the same key codes, but the keypress event will return other key codes, you have to check them yourself.

Fiddle

+5
source

Check if pressed

$(document).keyup(function(event) {
        if (event.which === 191 && event.shiftKey) {
            action();
        }
});

Please note that this is keyboard dependent, and it will be easier if you can use the event keypresslike fooobar.com/questions/1550193 / ... offered by

See http://unixpapa.com/js/key.html for details

+1
source

All Articles