Javascript examples for DOM:Key Event
KeyEvent charCode Property - Check keycode from key press event
<!DOCTYPE html> <html> <body> <p>Press the "o" key.</p> <input type="text" size="40" onkeypress="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {//from w ww .j a va 2 s . c om var x = event.charCode || event.keyCode; // o is 111 if (x == 111 ) { console.log("You pressed the 'o' key!"); } } </script> </body> </html>