Javascript examples for DOM:Key Event
The which property returns the Unicode character code of the key that triggered the onkeypress event.
The which property returns the Unicode key code of the key that triggered the onkeydown or onkeyup event.
Character codes is a number which represents an ASCII character.
Key codes is a number which represents an actual key on the keyboard.
This property is read-only.
A Number, representing either a Unicode character code or the Unicode key code
The following code shows how to get the Unicode value of the pressed keyboard key:
<!DOCTYPE html> <html> <body> <input type="text" size="40" onkeypress="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {/*from w ww .j av a 2s .c o m*/ var x = event.keyCode || event.which; var y = String.fromCharCode(x); document.getElementById("demo").innerHTML = "Number: " + x + " = Character: " + y; } </script> </body> </html>