I'm creating a text box for a user defined shortcut key combination, where it just prints out the modifiers and key.
I don't really care whether its set as you press or release the keys, so I started with the keypress event. Firstly, modifiers seemed to affect the keycode (such as shift giving caps which implies keycode is not a key code at all but a typed character code) but also preventDefault doesn't seem to work properly so I changed to keydown. This introduced a discrepancy in event.keyCode. For example, comma , produced a delightful ascii keyCode=44 but now it's a disgusting keyCode=188.
A test page: http://www.javascripter.net/faq/keyboardeventproperties.htm
I'd really like to have some standardized key codes here or at the very least some consistent ones. My request is for a workaround. Either:
What's the best way to get the printable character (ignoring modifiers, so
,/<are considered the same key and give,) for the weird but more consistentkeydown/keyup?Can
keypressbe made more likekeydown/keyupto actually give the key that was pressed and is there a mechanism likepreventDefaultto stop the browser intercepting shortcuts?