Thursday, April 28, 2011

'delete' doesn't trigger keypress events in JavaScript

http://unixpapa.com/js/key.html


pecial Keys
KeyASCIIMozilla keycodesIE keycodesOpera keycodespseudo ASCII codesexceptions
Insert-45454545Konqueror: 0
Opera < 9.0: 0
Delete-46464646Konqueror: 127
Opera < 9.0: 0
Home-36363636Opera < 9.0: 0
End-35353535Opera < 9.0: 0
Page Up-33333333
Page Down-34343434
Function Keys
F1 to F12
-112 to 123112 to 123112 to 123112 to 123
Keypad Keys


Some browsers avoid this problem by not generating keypress events for special keys. A good case can be made that this is the right thing to do, since these keystrokes are arguably not character events. But such arguments are weakened by the arbitrariness of the division between normal and special keys. Why should the keyboard Backspace key have a keypress event, but not the keypad Delete key? Is Tab really fundamentally different than right arrow?
keypress events
event.keyCodeevent.whichevent.charCode
Internet Explorer (Windows)normal:ASCII codeundefinedundefined
special:no keypress events for special keys
Internet Explorer (Mac)normal:ASCII codeundefinedASCII code
special:no keypress events for special keys
Geckonormal:zeroASCII codeASCII code
special:Mozilla keycodezerozero
WebKit ≥ 525normal:ASCII codeASCII codeASCII code
special:no keypress events for special keys
WebKit < 525normal:ASCII codeASCII codeASCII code
special:extended ASCII codeextended ASCII codeextended ASCII code
Opera ≥ 10.50 (all platforms)normal:ASCII codeASCII codeundefined
special:Mozilla keycode, except keypad and branded keys give Opera keycodeszeroundefined
Opera ≥ 9.50 (all platforms)
Opera 7 (Windows)
normal:ASCII codeASCII codeundefined
special:Mozilla keycode, except keypad and branded keys give Opera keycodeszero for arrows, function keys, PageUp, PageDown
same as event.keyCode otherwise
undefined
Opera 8.0 to 9.27 (Windows)normal:ASCII codeASCII codeundefined
special:Opera keycodezero for arrows, function keys, PageUp and PageDown,
same as event.keyCode otherwise
undefined
Opera < 9.50 (Linux & Macintosh)normal:ASCII codeASCII codeundefined
special:Opera keycodezero for arrows, function keys, PageUp and PageDown,
same as event.keyCode otherwise
undefined
Konqueror 4.3normal:ASCII codeASCII codeASCII code
special:Pseudo-ASCII codePseudo-ASCII codezero
Konqueror 3.5normal:ASCII codeASCII codeASCII code
special:Pseudo-ASCII codezerozero
Konqueror 3.2normal:ASCII codeASCII codeundefined
special:no keypress events for special keys

No comments:

Post a Comment