I’m trying to detect keyboard input and if the arrow keys are pressed, set the players next move to whatever was pressed. I’m listening for keyboard input using:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
This is the function that gets called:
public function keyDown(event:KeyboardEvent):void
{
switch (event.charCode)
{
case 37:
this.nextMove = "LEFT";
break;
case 38:
this.nextMove = "UP";
break;
case 39:
this.nextMove = "RIGHT";
break;
case 40:
this.nextMove = "DOWN";
break;
}
trace(event.charCode);
}
Thing is, charCode is always 0. What’s the reason for this?
Use
keyCodefor what you’re doing.