Capturing multiples keystrokes in Javascript
I'm trying to do a Javascript application that needs this particular feature:
Whenever the user presses one of the arrow keys, it must act according to the key direction.
And if the user press a key, hold it down, and press a second one, then, only the action of the second one must be executed until released. And if the first one stills pressed, it's action must be executed again.
The problem is that when you press the second key, no more events (except key up) of the first key is fired, even开发者_Go百科 after releasing the second one.
Here is more or less what I'm doing: http://jsbin.com/amajo4
It doesn't need to work in IE, though IE8 support could be cool, IE7 and IE6 are completely discarded :) But it must be done in Javascript, no flash or Silverlight.
.
You can use setInterval
to run your handler every (eg) 400 ms, then maintain a stack of pressed keys by handling keydown and keyup.
精彩评论