views:

55

answers:

2

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 acording 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 seccond 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 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 completly discarted :) But it must be done in javascript, no flash or silverlight.

Thanks!

A: 

You don't. You use Flash instead. And I wouldn't be surpised if any 'solutions' were very browser dependent.

Crusader
It can be done using javascript, pls make sure try to answer the question before commenting anything else.
Bang Dao
Fine, the answer is, it's a terrible idea and you shouldn't be doing it in the first place. It's going to break some day. Can we get some more downvotes from sobbing "JavaScript engineers" still in denial?
Crusader
It's not a bad idea at all, and it's very possible cross-browser.
SLaks
It's more cross browser and future-proof (future new browser and new browser version) than any slapped together JavaScript solution would be, but most "JavaScript engineers" don't like to hear that their skill set is outdated by virtual machine 'rich client' technology such as Flash/Flex, Silverlight, and JavaFX--thus the downvotes. What a shame.
Crusader
+4  A: 

You can use setInterval to run your handler every (eg) 400 ms, then maintain a stack of pressed keys by handling keydown and keyup.

SLaks
This seams to be the way to go =)
alcuadrado