JavaScript keyCode - keystroke, using foreign keyboard layouts

Could not find a solution to what seems like a simple problem to me.

I use var a = evt.keyCode;to determine which key was pressed.

The problem is that the value I get is the ASCII code of the clicked key, and not the one that was pressed.

If, for example, the user uses a French keyboard, pressing a key , so instead of getting the ASCII code, I get 55, which is the ASCII code . 7 é é 7

+3
source share
2 answers

onkeypress onkeydown? , onkeypress, . event.which event.keyCode:

function whichKey(evt) {
    alert(String.fromCharCode(evt.which || evt.keyCode));
}

: http://jsfiddle.net/7LsMk/

+6

: var unicode=evt.charCode? evt.charCode : evt.keyCode; var actualkey=String.fromCharCode(unicode);

0

Source: https://habr.com/ru/post/1790738/


All Articles