I noticed some weird behavior with keyboard input in JavaScript. Perhaps I am missing something really obvious, but are there any rules regarding which keys can be pressed at the same time?
I use boolean variables to save state for each of the four keys, as shown below, this allows you to use many simultaneous keystrokes (hardware resolution):
var up = false, left = false, right = false, space = false;
function keydown(e) {
if (e.keyCode == 32)
space = true;
if (e.keyCode == 38)
up = true;
if (e.keyCode == 37)
left = true;
if (e.keyCode == 39)
right = true;
}
function keyup(e) {
if (e.keyCode == 32)
space = false;
if (e.keyCode == 38)
up = false;
if (e.keyCode == 37)
left = false;
if (e.keyCode == 39)
right = false;
}
On the two machines I tried, the following jsfiddle allows you to simultaneously press the spacebar, up and right, but not space, but up and left. On these two machines, it does the same in Chrome, FF, and IE. It works flawlessly on the third machine, and I can hold all 4 keys at the same time.
, , - ? , , , .
http://jsfiddle.net/SYs5b/
( , )