PDA

View Full Version : Key.isDown overload


Stoev
11-08-2004, 03:08 PM
Hi everyone.

It is my experince that when you use the Key.isDown method it can only handle 3 keys at once. If you press 4 keys at the same time, one of the keys is just ignored. This is a big problem in a 2-player game.

I also tried to use a listener that changed the value of an array, so that the onEnterFrame event checked the array rather than the Key.isDown.

x = new Array( 6 );

mc.onEnterFrame = function() {
if (x[0] == 1) this.mc_1._alpha = 50;
else this.mc_1._alpha = 100;
if (x[1] == 1) this.mc_2._alpha = 50;
else this.mc_2._alpha = 100;
if (x[2] == 1) this.mc_3._alpha = 50;
else this.mc_3._alpha = 100;
if (x[3] == 1) this.mc_4._alpha = 50;
else this.mc_4._alpha = 100;
if (x[4] == 1) this.mc_5._alpha = 50;
else this.mc_5._alpha = 100;
if (x[5] == 1) this.mc_6._alpha = 50;
else this.mc_6._alpha = 100;
}

mc.onKeyDown = function() {
if (Key.getCode() == 65) x[0] = 1;
if (Key.getCode() == 83) x[1] = 1;
if (Key.getCode() == 68) x[2] = 1;
if (Key.getCode() == 100) x[3] = 1;
if (Key.getCode() == 101) x[4] = 1;
if (Key.getCode() == 102) x[5] = 1;
}

mc.onKeyUp = function() {
if (Key.getCode() == 65) x[0] = 0;
if (Key.getCode() == 83) x[1] = 0;
if (Key.getCode() == 68) x[2] = 0;
if (Key.getCode() == 100) x[3] = 0;
if (Key.getCode() == 101) x[4] = 0;
if (Key.getCode() == 102) x[5] = 0;
}

Key.addListener( mc );

But it made no difference.

Does anyone know if it is even possible to detect more than 3 keys at once?

Stoev

ChopperDave
11-11-2004, 09:51 PM
I had a little more luck than that, but I still could not get anymore than 5 or 6 depending on which keys were pressed down and what order they were pressed.

key = [];
this.onEnterFrame = function() {
myListener = new Object();
myListener.onKeyDown = function() {
key[Key.getCode()] = 1;
_root.text.text = Key.getCode();
};
for (i=0; i<key.length; i++) {
if (key[i] == 1) {
setProperty(i, _alpha, 100);
} else {
setProperty(i, _alpha, 50);
}
}
myListener.onKeyUp = function() {
key[Key.getCode()] = 0;
};
Key.addListener(myListener);
};

The file is just a bunch of squares aranged like a keyboard. They have thier keycode value as thier instance name. If you need to see the program pm me and I can send it to you. But like I said I couldn't get more than a few to register at a time.