The keydown, keypress and keyup events fire when the user presses a key.
The keydown/keypress scheme outlined above is originally a Microsoft invention that Safari 3.1 copied for reasons explained by Alexey Proskuryakov of the Safari team.
The great advantage of this theory is that it clearly explains why we need keydown and keypress to be two separate events; without some sort of difference between the two events it's rather pointless to keep both of them around.
Meanwhile the spec has also gone over to this scheme of things. Firefox and Opera still don’t get it, but they are simply wrong.
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
On the window
|
No | Yes | Yes | Yes | Yes | Yes | ||||||||
Are these events available on the window? |
||||||||||||||
On the document
|
Yes | Yes | Yes | Yes | Yes | |||||||||
Are these events available on the document? |
||||||||||||||
On a form
|
Yes | Yes | Yes | Yes | Yes | |||||||||
Are these events available on a form? |
||||||||||||||
On focusable elements
|
Yes | Yes | Yes | Yes | Yes | |||||||||
An important point of these events is monitoring user input in text inputs. Key events on other focusable elements such as links and radio buttons and such don't make much sense to me, but all browsers support them. |
||||||||||||||
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |
Special keys
When the user presses special keys such as the arrow keys, the browser should NOT fire keypress events. |
Yes | Incor |
Yes | Yes | Incor |
|||||||||
I tested this with the arrow-left and the Shift keys. In both cases
only the keydown event should fire.
|
||||||||||||||
Repeats
When the user keeps a key depressed, the keydown and keypress events, if applicable, should fire continuously. |
Yes | Yes | Yes | Yes | Incor |
|||||||||
I tested this with three keys:
|
||||||||||||||
Event bubbling
The event should bubble. |
Yes | Yes | Yes | Yes | Yes | |||||||||
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |
Prevent default keydown
|
Yes | Yes | Yes | Yes | No | |||||||||
I tested this with two keys:
|
||||||||||||||
Prevent default keypress
Default of special keys should NOT be prevented |
Yes | Incor |
Yes | Yes | Incor |
|||||||||
I tested this with two keys:
|
||||||||||||||
Prevent default keyup
“No” is the correct answer
|
No | No | No | No | No | |||||||||
I tested this with two keys:
|
||||||||||||||
textinput
See above for definition
|
No | No | Yes | Yes | No | |||||||||
Only works with addEventListener. Default is preventable: the character is not added. |
||||||||||||||
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |