keydown() and holding in a key
$(document).keydown(myOnKeyDownFunction);
开发者_StackOverflowI notice that in Chrome 10.0 and Firefox 3.6 (both in Ubuntu), after registering a listener for keydown, the callback is invoked once immediately, followed by a short delay, and then triggered again repeatedly until the key is released. For my current project, this sure makes my life easier... but can I expect it to behave like that for all browsers?
There's a (possibly out-of-date) summary of how various browsers handle key presses and keyboard auto-repeat at http://unixpapa.com/js/key.html
It should be the same for all browsers since this event should mirror the keyboards repeat buffer.
Try to put your cursor in any text field and look how the flow of letters are when you just hold down a key - it is exactly like your describe.
精彩评论