Advertisement
Guest User

KeyManager

a guest
Jul 7th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  libTF.interfaces
  2. {
  3.     import flash.display.Stage;
  4.     import flash.events.KeyboardEvent;
  5.    
  6.     public class KeyManager
  7.     {
  8.        
  9.         public static var keys:Vector.<Boolean>;
  10.        
  11.         public static function init(stage:Stage):void
  12.         {
  13.             keys = new Vector.<Boolean>(256);
  14.             stage.addEventListener(KeyboardEvent.KEY_DOWN, pressed);
  15.             stage.addEventListener(KeyboardEvent.KEY_UP, released);
  16.         }
  17.        
  18.         private static function pressed(e:KeyboardEvent):void
  19.         {
  20.             keys[e.keyCode] = true;
  21.         }
  22.        
  23.         private static function released(e:KeyboardEvent):void
  24.         {
  25.             keys[e.keyCode] = false;
  26.         }
  27.        
  28.         public static function isPressed(val:int):Boolean
  29.         {
  30.             if (val > 255) { return false; }
  31.             return keys[val];
  32.         }
  33.        
  34.         public static function isPressedStr(val:String):Boolean
  35.         {
  36.             return isPressed(val.toUpperCase().charCodeAt(0));
  37.         }
  38.        
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement