event.which

event.which Returns: String

Description: For key or button events, this attribute indicates the specific button or key that was pressed.

  • version added: 1.1.3event.which

event.which normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input. For more detail, read about event.charCode on the MDC.

Example:

Log what key was depressed.

<!DOCTYPE html>
<html>
<head>
  <script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<input id="whichkey" value="type something">
<div id="log"></div>
<script>$('#whichkey').bind('keydown',function(e){
  $('#log').html(e.type + ': ' +  e.which );
});  </script>
</body>
</html>

Demo:

Result:

"keydown" 74