Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package input
- {
- import flash.display.Stage;
- import flash.events.KeyboardEvent;
- /**
- * ...
- * @author Yury Grigoryev
- */
- public class Input
- {
- private static var _stage: Stage;
- private static var _keyDownStatus: Array;
- public function Input()
- {
- }
- public static function init(stg: Stage):void
- {
- _stage = stg;
- _keyDownStatus = new Array(500);
- for each( var status: Boolean in _keyDownStatus ) {
- status = false;
- }
- _stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
- _stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
- }
- public static function isKeyDown( key:int ): Boolean
- {
- return _keyDownStatus[ key ];
- }
- public static function isKeyUp( key:int ): Boolean
- {
- return !_keyDownStatus[ key ];
- }
- private static function keyDownHandler( event: KeyboardEvent ):void
- {
- _keyDownStatus[ event.keyCode ] = true;
- }
- private static function keyUpHandler( event: KeyboardEvent ):void
- {
- _keyDownStatus[ event.keyCode ] = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement