Here’s something that came up at Jot last week. Which event will be fired continuously, if you hold down a key: onkeydown or onkeypress?
The answer is that it depends on both platform and browser. In general, Windows-based browsers fire only onkeydown, except for Firefox/Win which also fires onkeypress. On the Mac and on Linux, only onkeypress is fired, and onkeydown is not fired on the Firefox browser for these platforms. Something to keep in mind when you bind the “iterate over items while holding arrow up or down key” behaviour to your application. See the testcase.
And it depends on the key. IE fires onkeypress repeatedly as well for keys that produce characters.
Looking at your testcase with Firefox 1.5.0.4 in WinXP SP2, I get both onkeydown and onkeypress for:
I get onkeydown but not onkeypress for:
I get neither event for PrtScr and the Windows key.
Sjoerd, indeed. It gets stranger and stranger still.
Nick, it would seem like Firefox/Win tries to emulate IE behaviour, but fails for certain keys. On the Mac, no modifier keys fire events.
I would guess it’s more likely that FF/win behaves differently due to the key events being different in Windows vs. OS X than trying to be different on the two platforms.
Yes, but it is odd that Firefox/Win does not simulate any other browser on that platform, while Firefox/Mac behaves like all other browsers.