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.
In contrast, Firefox and Opera just fire a bunch of key events without plan or purpose. There are historical reasons for this (everybody expects the keydown and keypress events to be available), but they aren't very strong because IE has always supported the scheme outlined above, and therefore web developers were forced to do the same.
Therefore I consider the IE/Safari theory to be the correct implementation, which Firefox and Opera will have to conform to. (The W3C spec is no help here; it doesn't even mention the keypress event.)
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
On the window
|
No | Yes | Yes | Minimal | 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. |
||||||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|
Repeats
When the user keeps a key depressed, both the keydown and (if it's a character key) the keypress event should fire continuously. |
Yes | Yes | Yes | Untest |
Incor |
Incor |
||||||||
|
||||||||||||||
|
Special keys
When the user presses special keys such as the arrow keys, the browser should NOT fire keypress events. |
Yes | Too many | Too many | Yes | Untest |
Incor |
Incor |
|||||||
|
||||||||||||||
|
Event bubbling
The event should bubble. |
Yes | Yes | Yes | Yes | Yes | |||||||||
|
||||||||||||||
|
Prevent default keydown
|
Yes | Yes | Yes | No | Yes | |||||||||
|
This should prevent the default of any key. |
||||||||||||||
|
Prevent default keypress
Default of special keys should NOT be prevented |
Yes | Incor |
Incor |
Yes | Untest |
No | Incor |
Yes | ||||||
|
This should prevent the default of keys that lead to a character being inserted.
|
||||||||||||||
|
Prevent default keyup
“No” is the correct answer
|
No | No | No | No | No | |||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
Safari iPhone doesn’t support keypress. Furthermore, it’s not possible to repeat a character by keeping a key depressed.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
textInput
Equivalent of keypress. |
No | No | Yes | No | No | |||||||||
This is a DOM event, despite the "DOM" bit missing in the name. Therefore it does not work with traditional event registration. |
||||||||||||||