Keycode detection on AZERTY vs. QWERTY


How can I in JavaScript detect the typing of a question mark on AZERTY keyboard ? On QWERTY keyboard a question mark produces the code 191, but on AZERTY it seems to produce code 188 (comma on QWERTY). Or should I distinguish between both keyboards in JavaScript, but how ?

H. Franken

Posted 2017-08-10T09:41:46.113




The fastest solution I can think of is to compare the key with the actual question mark, so something like this would be a good solution.

document.addEventListener('keydown', function(event) {
    if (event.key && event.key === '?') {
        // your code goes here
}, true);

Dawid ZbiƄski

Posted 2017-08-10T09:41:46.113

Reputation: 1 364


If you want to detect the character being typed, use KeyboardEvent.key, not KeyboardEvent.code -- the key property will contain either the character that was typed (like "?"), or a string like "Shift" or "ArrowUp" for special keys. The location of the key on the keyboard won't affect the result.

$("#f").on("keydown", function(ev) {
  return false;
<script src=""></script>

<input id="f" autocomplete="off">


Posted 2017-08-10T09:41:46.113

Reputation: 144 555