Visit Mozilla.org

DOM:event.which

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.

[edit] Syntax

keyResult = event.which

keyResult contains the numeric code for a particular key pressed, depending on whether an alphanumeric or non-alphanumeric key was pressed. Please see charCode and keyCode for more details.

[edit] Example

<html>
<head>
<title>charCode/keyCode/which example</title>

<script type="text/javascript">

function showKeyPress(evt)
{
alert("onkeypress handler: \n"
      + "keyCode property: " + evt.keyCode + "\n"
      + "which property: " + evt.which + "\n"
      + "charCode property: " + evt.charCode + "\n"
      + "Character Key Pressed: "
      + String.fromCharCode(evt.charCode) + "\n"
     );
}


function keyDown(evt)
{
alert("onkeydown handler: \n"
      + "keyCode property: " + evt.keyCode + "\n"
      + "which property: " + evt.which + "\n"
     );
}


</script>
</head>

<body
 onkeypress="showKeyPress(event);"
 onkeydown="keyDown(event);"
>

<p>Please press any key.</p>

</body>
</html>

[edit] Specification

Not part of any specification.