How to get the pressed key code using jQuery ?

Getting key code in jQuery


event.keyCode returns the Unicode value of a non-character key in a KeyPress events.

Example jQuery code to get pressed key code

      <title>The jQuery Example - To get key code</title>

      <script src=""></script>		
      <script type = "text/javascript">
        function get_key_code(event) {
          var code = event.keyCode;
          $('span').text("Key code is: " + code);
          $('span').css('color', 'blue');

   <p>Test Section</p>
<p>Please enter the key to get pressed key code, 
<input type="text" onkeydown="get_key_code(event);"/></p>
pressed key code output

event.keyCode- returns the pressed key code in the textbox.

here input a letter 'A' is pressed in the text field and returns a 'Key code is 65'.

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter