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 ?
Asked
Active
Viewed 2,154 times
1
-
You could spy on the key pressed down when typing certain characters. Like QWERTY it would be the `Shift` and the `/` key. But I guess only `Shift` would be visible. But I don't know of any way you could certainly tell which layout is used using JavaScript – lumio Aug 10 '17 at 22:07
2 Answers
0
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
- 5,521
- 8
- 43
- 70
0
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) {
$(this).val(ev.key);
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="f" autocomplete="off">