I’d just like to know the range(s) of JavaScript keyCodes that correspond to typeable characters; or alternatively, the range of non-typeable (control) characters like backspace, escape, command, shift, etc. so I can ignore them.
The reason I ask is calling String.fromCharCode() is resulting in odd characters for control keys. For example I get “[” for left command, “%” for left arrow. Weirdness like that.
Keydown will give you the keyCode of the key pressed, without any modifications.
Only the number keys, letter keys, and spacebar will have keycodes correlating to
String.fromCharCodeas it uses Unicode values.Keypress will be the charCode representation of the text entered. Note that this event won’t fire if no text is “printed” as a result of the keypress.
http://jsfiddle.net/LZs2D/1/ Will demonstrate how these work.
KeyUp behaves similarly to KeyDown.