Get the key pressed on keyup or keypress event when key is pressed - Javascript DOM Event

Javascript examples for DOM Event:onkeyup

Description

Get the key pressed on keyup or keypress event when key is pressed

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body onkeypress="showKeyCode(event);">   
      <title>keyCode example</title> 
      <script type="text/javascript">
function showKeyCode(e)/* w  w w.j a  v a2  s.  co m*/
{
  var code = window.event ? event.keyCode : e.which
  console.log("keyCode for the key pressed: " + code + "\n");
}

      </script>   
      <p>Press any key.</p>    
   </body>
</html>

Related Tutorials