asp.net.ph

Skip Navigation Links

keyCode Property

event Properties   DHTML Events


Sets or retrieves the Unicode key code associated with the key that caused the event.

Syntax


HTML N/A
Script event.keyCode [ = sKeyCode ]

Possible Values


sKeyCode String containing the Unicode key code.

The property is read/write with no default value.

Remarks

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.

Remarks

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.

Applies To

event

See Also

charCodeAt, Key Capture Routines



>

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note