Unicode search for keystroke in javascript

How to detect Unicode key pressed in javascript?

I googled on this and most of the results will only answer how to find keyCode. Any help would be greatly appreciated.

+3
source share
1 answer

In theory, according to DOM3 Events , you should use the property keyof the event object. In practice, this does not work, with the exception of fairly new versions of IE.

A practical approach is to use a property whichor property charCode, although the DOM3 Events project frowns at them:

, keyCode, charCode which.

, : keyCode - . charCode - ASCII . which - , , . , , , .

charCode Unicode ( ).

( ):

<style>
#o { border: solid black 1px; }
</style>
<input id=i>
<div id=o></div>
<script>
document.getElementById('i').onkeypress = function (e) {
  var ev = e || window.event;
  document.getElementById('o').innerHTML += 
    ev.charCode + ' '; 
}
</script>

, , , IE 9 . - keyCode .

+1

All Articles