Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package libTF.interfaces
- {
- import flash.display.Stage;
- import flash.events.KeyboardEvent;
- public class KeyManager
- {
- public static var keys:Vector.<Boolean>;
- public static function init(stage:Stage):void
- {
- keys = new Vector.<Boolean>(256);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, pressed);
- stage.addEventListener(KeyboardEvent.KEY_UP, released);
- }
- private static function pressed(e:KeyboardEvent):void
- {
- keys[e.keyCode] = true;
- }
- private static function released(e:KeyboardEvent):void
- {
- keys[e.keyCode] = false;
- }
- public static function isPressed(val:int):Boolean
- {
- if (val > 255) { return false; }
- return keys[val];
- }
- public static function isPressedStr(val:String):Boolean
- {
- return isPressed(val.toUpperCase().charCodeAt(0));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement