Strange Behavior Between onkeydown And onkeypress Events

A strange behavior between onkeydown and onkeypress events in JavaScript has been noticed. Here is a function to find out the keycode:

; function getCode(e)
{
; var evt = window.event ? event : e
; var code
; if(window.event) code = evt.keyCode
else code = evt.which
; return code
}

If the event is onkeypress, this function would generate ASCII key code. However, if the event is onkeydown, this function would generate JavaScript keycode, which does not discriminated the cases. Indeed, the latter generate keycode for capital case only.

No comments:

Post a Comment

Labels