2bam

GameInput info dump

Feb 26th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.Sprite;
  3.     import flash.events.Event;
  4.     import flash.events.GameInputEvent;
  5.     import flash.text.TextField;
  6.     import flash.text.TextFormat;
  7.     import flash.ui.GameInput;
  8.     import flash.ui.GameInputControl;
  9.     import flash.ui.GameInputDevice;
  10.     /**
  11.      * ...
  12.      * @author 2bam.com
  13.      */
  14.     public class Main extends Sprite {
  15.        
  16.         private var _tf:TextField;
  17.         private var _gi:GameInput;
  18.         private var _myCount:int = 0;
  19.        
  20.         private function onAdd(ev:GameInputEvent):void {
  21.             _myCount++;
  22.         }
  23.        
  24.         private function onRem(ev:GameInputEvent):void {
  25.             _myCount--;
  26.         }
  27.        
  28.         private function onFrame(ev:Event):void {
  29.             var s:String;
  30.             s = "GameInput "+(GameInput.isSupported?"":"NOT")+" supported\n";
  31.             s += "GameInput.numDevices = "+GameInput.numDevices+"\n";
  32.             s += "_myCount = "+_myCount+"\n";
  33.             for(var i:int = 0; i<GameInput.numDevices; i++) {
  34.                 var dev:GameInputDevice = GameInput.getDeviceAt(i);
  35.                 s += "======="+i+"=======\n";
  36.                 s += "\tname: "+dev.name+"\n";
  37.                 s += "\t  id: "+dev.id+"\n";
  38.                 s += "\t#ctl: "+dev.numControls+"\n";
  39.                 dev.enabled = true;
  40.                 for(var j:int = 0; j<dev.numControls; j++) {
  41.                     var ctl:GameInputControl = dev.getControlAt(j);
  42.                     s += "\t\tCTL "+j+" id:"+ctl.id+" value:"+ctl.value+"\n";
  43.                 }
  44.             }
  45.            
  46.                        
  47.            
  48.             _tf.text = s;
  49.         }
  50.        
  51.        
  52.         public function Main() {
  53.             _tf = new TextField;
  54.             _tf.multiline = true;
  55.             _tf.wordWrap = true;
  56.             //_tf.defaultTextFormat = new TextFormat("Courier New", 16);
  57.             _tf.defaultTextFormat = new TextFormat("Courier New", 11);
  58.             _tf.width = stage.stageWidth;
  59.             _tf.height = stage.stageHeight;
  60.             addChild(_tf);
  61.             stage.addEventListener(Event.ENTER_FRAME, onFrame);
  62.            
  63.             _gi = new GameInput;
  64.             _gi.addEventListener(GameInputEvent.DEVICE_ADDED, onAdd,false,0,true);
  65.             _gi.addEventListener(GameInputEvent.DEVICE_REMOVED, onRem,false,0,true);
  66.         }
  67.        
  68.     }
  69.  
  70. }
Add Comment
Please, Sign In to add comment