Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.GameInputEvent;
- import flash.text.TextField;
- import flash.text.TextFormat;
- import flash.ui.GameInput;
- import flash.ui.GameInputControl;
- import flash.ui.GameInputDevice;
- /**
- * ...
- * @author 2bam.com
- */
- public class Main extends Sprite {
- private var _tf:TextField;
- private var _gi:GameInput;
- private var _myCount:int = 0;
- private function onAdd(ev:GameInputEvent):void {
- _myCount++;
- }
- private function onRem(ev:GameInputEvent):void {
- _myCount--;
- }
- private function onFrame(ev:Event):void {
- var s:String;
- s = "GameInput "+(GameInput.isSupported?"":"NOT")+" supported\n";
- s += "GameInput.numDevices = "+GameInput.numDevices+"\n";
- s += "_myCount = "+_myCount+"\n";
- for(var i:int = 0; i<GameInput.numDevices; i++) {
- var dev:GameInputDevice = GameInput.getDeviceAt(i);
- s += "======="+i+"=======\n";
- s += "\tname: "+dev.name+"\n";
- s += "\t id: "+dev.id+"\n";
- s += "\t#ctl: "+dev.numControls+"\n";
- dev.enabled = true;
- for(var j:int = 0; j<dev.numControls; j++) {
- var ctl:GameInputControl = dev.getControlAt(j);
- s += "\t\tCTL "+j+" id:"+ctl.id+" value:"+ctl.value+"\n";
- }
- }
- _tf.text = s;
- }
- public function Main() {
- _tf = new TextField;
- _tf.multiline = true;
- _tf.wordWrap = true;
- //_tf.defaultTextFormat = new TextFormat("Courier New", 16);
- _tf.defaultTextFormat = new TextFormat("Courier New", 11);
- _tf.width = stage.stageWidth;
- _tf.height = stage.stageHeight;
- addChild(_tf);
- stage.addEventListener(Event.ENTER_FRAME, onFrame);
- _gi = new GameInput;
- _gi.addEventListener(GameInputEvent.DEVICE_ADDED, onAdd,false,0,true);
- _gi.addEventListener(GameInputEvent.DEVICE_REMOVED, onRem,false,0,true);
- }
- }
- }
Add Comment
Please, Sign In to add comment