event Properties DHTML Events
Sets or retrieves the Unicode key code associated with the key that caused the event.
HTML |
N/A |
Script |
event.keyCode [ = sKeyCode ] |
sKeyCode |
String containing the Unicode key code. |
The property is read/write with no default value.
The property is intended to be used with the onkeydown, onkeyup, and onkeypress events.
The property's value is 0
( zero ) if no key caused the event.
The below code shows a cross-browser method for capturing the onkeydown event at the document level and identifying all the Unicode values of a standard US-English keyboard. Note that Netscape® 4 does not return key codes with certain keys.
<script language="JavaScript">
<!--
document.onkeydown
= function ( evt ) {
var keyCode = document.all ? event.keyCode :
document.getElementById ? evt.keyCode :
document.layers ? evt.which : 0;
alert ( keyCode );
return false;
}
//-->
</script>
To test, press any key to get its correspondng keyCode.
event
charCodeAt, Key Capture Routines