Javascript examples for DOM:Key Event
The key property returns the identifier of the key pressed.
This property is read-only.
A String, representing the pressed keyboard button.
The return value of this property can be a string of:
The following code shows how to get the key pressed.
<!DOCTYPE html> <html> <body> <input type="text" size="40" onkeypress="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {/*www . java 2 s . co m*/ var x = event.keyCode; var y = String.fromCharCode(x); document.getElementById("demo").innerHTML = "Number: " + x + " = Character: " + y; } </script> </body> </html>