I'm developing a little game. I use the following code to detect the keys pressed by the player:
private function onKeyDown(event:KeyboardEvent):void {
//moviment keys
if (event.keyCode == 37 || event.keyCode == 65) {
this.leftKeyPressed = true;
}
if (event.keyCode == 39 || event.keyCode == 68) {
this.rightKeyPressed = true;
}
if (event.keyCode == 38 || event.keyCode == 87) {
this.upKeyPressed = true;
}
if (event.keyCode == 40 || event.keyCode == 83) {
this.downKeyPressed = true;
}
if (event.keyCode == this.shootKey) {
this.shootKeyPressed = true;
}
}
The onKeyUp event:
private function onKeyUp(event:KeyboardEvent):void {
if (event.keyCode == 37 || event.keyCode == 65) {
this.leftKeyPressed = false;
}
if (event.keyCode == 39 || event.keyCode == 68) {
this.rightKeyPressed = false;
}
if (event.keyCode == 38 || event.keyCode == 87) {
this.upKeyPressed = false;
}
if (event.keyCode == 40 || event.keyCode == 83) {
this.downKeyPressed = false;
}
if (event.keyCode == this.shootKey) {
this.shootKeyPressed = false;
}
if (event.keyCode == changeColorKey) {
trace('color key released');
trace(getTimer());
this.changeColorKeyPressed = true;
}
}
Basically the shootKey will be hold down by the player almost all the time. And the changeColorKey will be pressed very often but not hold down. While testing I noted that holding the shootKey and the right arrow down, the onKeyUp events for the changeColorKey don't get fired. Holding the up or down arrow key instead of the right arrow has the same effect. If I hold the left arrow key the events get fired. Why does it occour? Is there something wrong with my code?