I just got started learning AS3.
Let\'s say I have two textfields on my sprite.
I like to move textfield 1 when I press left or right arrow keys, but I also
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
/**
* ...
* @author www0z0k
*/
public class KeyExample extends Sprite {
private var _theyArePressed:Object = { };
public function KeyExample() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
}
private function onUp(e:KeyboardEvent):void {
_theyArePressed[e.keyCode] = false;
}
private function onDown(e:KeyboardEvent):void {
_theyArePressed[e.keyCode] = true;
if (_theyArePressed[Keyboard.SPACE] && _theyArePressed[Keyboard.UP]) {
//do anything
}
}
}
}
but keep in mind that that AFAIK keyboards can handle limited quantity of keys pressed at the same time, depending on the hardware