<commit_before>package com.zehfernando.input.binding {
	import com.zehfernando.signals.SimpleSignal;

	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.GameInputEvent;
	import flash.events.KeyboardEvent;
	import flash.ui.GameInput;
	import flash.ui.GameInputControl;
	import flash.ui.GameInputDevice;
	import flash.utils.getTimer;
	/**
	 * @author <NAME>
	 */
	public class KeyActionBinder {

		// Provides universal input control for game controllers and keyboard
		// http://zehfernando.com/2013/abstracting-key-and-game-controller-inputs-in-adobe-air/
		// http://zehfernando.com/2013/keyactionbinder-updates-time-sensitive-activations-new-constants/

		// TODO:
		// * Allow sensitive controls to be treated as normal controls (with a threshold)
		// * Think of a way to avoid axis injecting button pressed
		// * Add gamepad index to return signals, and rethink whether gamepad index should be part of isActionActivated() and getActionValue() instead
		// * Use caching samples?
		// * Allow "any" gamepad key (for "press any key")
		// * Add missing asdocs
		// * Better multi-platform setup... re-think GamepadControls

		// * Auto controls
		// * Gamepad on isActivated()
		// * Thresholds

		// Versions:
		// 2013-10-08	1.0.0	First version to have a version number

		// Constants
		public static const VERSION:String = "1.0.0";

		private static var stage:Stage;

		// Properties
		private var _isRunning:Boolean;
		private var alwaysPreventDefault:Boolean;						// If true, prevent action by other keys all the time (e.g. menu key)

		// Instances
		private var bindings:Vector.<BindingInfo>;						// Actual existing bindings, their action, and whether they're activated or not
		private var actionsActivations:Object;							// How many activations each action has (key string with ActivationInfo instance)

		private var _onActionActivated:SimpleSignal;					// Receives: action:String
		private var _onActionDeactivated:SimpleSignal;					// Receives: action:String
		private var _onSensitiveActionChanged:SimpleSignal;				// Receives: action:String, value:Number (0-1)

		private var gameInputDevices:Vector.<GameInputDevice>;

		private static var gameInput:GameInput;

		private var ii:int;												// Internal i, for speed
		private var it:int;												// Internal t, for speed

		// ================================================================================================================
		// STATIC CONSTRUCTOR ---------------------------------------------------------------------------------------------

		public static function init(__stage:Stage):void  {
			stage = __stage;

			if (GameInput.isSupported) gameInput = new GameInput();
		}

		// ================================================================================================================
		// CONSTRUCTOR ----------------------------------------------------------------------------------------------------

		public function KeyActionBinder() {
			alwaysPreventDefault = true;
			bindings = new Vector.<BindingInfo>();
			actionsActivations = {};

			_onActionActivated = new SimpleSignal();
			_onActionDeactivated = new SimpleSignal();
			_onSensitiveActionChanged = new SimpleSignal();

			start();<commit_msg>Created initial list of auto gamepad controls<commit_after>package com.zehfernando.input.binding {
	import com.zehfernando.signals.SimpleSignal;

	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.GameInputEvent;
	import flash.events.KeyboardEvent;
	import flash.ui.GameInput;
	import flash.ui.GameInputControl;
	import flash.ui.GameInputDevice;
	import flash.ui.KeyLocation;
	import flash.ui.Keyboard;
	import flash.utils.getTimer;
	/**
	 * @author <NAME>
	 */
	public class KeyActionBinder {

		// Provides universal input control for game controllers and keyboard
		// http://zehfernando.com/2013/abstracting-key-and-game-controller-inputs-in-adobe-air/
		// http://zehfernando.com/2013/keyactionbinder-updates-time-sensitive-activations-new-constants/

		// TODO:
		// * Allow sensitive controls to be treated as normal controls (with a threshold)
		// * Think of a way to avoid axis injecting button pressed
		// * Add gamepad index to return signals, and rethink whether gamepad index should be part of isActionActivated() and getActionValue() instead
		// * Use caching samples?
		// * Allow "any" gamepad key (for "press any key")
		// * Add missing asdocs
		// * Better multi-platform setup... re-think GamepadControls

		// * Auto controls
		// * Gamepad on isActivated()
		// * Thresholds

		// Versions:
		// 2013-10-08	1.0.0	First version to have a version number

		// Constants
		public static const VERSION:String = "1.0.0";

		private static var stage:Stage;

		// Properties
		private var _isRunning:Boolean;
		private var alwaysPreventDefault:Boolean;						// If true, prevent action by other keys all the time (e.g. menu key)

		// Instances
		private var bindings:Vector.<BindingInfo>;						// Actual existing bindings, their action, and whether they're activated or not
		private var actionsActivations:Object;							// How many activations each action has (key string with ActivationInfo instance)

		private var _onActionActivated:SimpleSignal;					// Receives: action:String
		private var _onActionDeactivated:SimpleSignal;					// Receives: action:String
		private var _onSensitiveActionChanged:SimpleSignal;				// Receives: action:String, value:Number (0-1)

		private var gameInputDevices:Vector.<GameInputDevice>;

		private static var gameInput:GameInput;

		private var ii:int;												// Internal i, for speed
		private var it:int;												// Internal t, for speed

		// ================================================================================================================
		// STATIC CONSTRUCTOR ---------------------------------------------------------------------------------------------

		public static function init(__stage:Stage):void  {
			stage = __stage;

			if (GameInput.isSupported) gameInput = new GameInput();

			// Creates a list of all known gamepads via a more readable/editable initializer
			var platformsObj:Object = {
				"windows7" : {
					"filters" : {
						"manufacturer"		: "Adobe Windows",
						"os"				: "Windows 7",
						"version"			: "WIN"
					},
					"gamepads" : {
						"xbox360" : {
							"filters" : {
								"name"			: "Xbox 360 Controller"
							},
							"controls" : {
								"AXIS_0"		: [GamepadControls.STICK_LEFT_X,			-1,	1],
								"AXIS_1"		: [GamepadControls.STICK_LEFT_Y,			 1,	-1],
								"AXIS_2"		: [GamepadControls.STICK_RIGHT_X,			-1,	1],
								"AXIS_3"		: [GamepadControls.STICK_RIGHT_Y,			 1,	-1],
								"BUTTON_4"		: [GamepadControls.ACTION_DOWN,				 0,	1],
								"BUTTON_5"		: [GamepadControls.ACTION_RIGHT,			 0,	1],
								"BUTTON_6"		: [GamepadControls.ACTION_LEFT,				 0,	1],
								"BUTTON_7"		: [GamepadControls.ACTION_UP,				 0,	1],
								"BUTTON_4"		: [GamepadControls.DPAD_UP,					 0,	1],
								"BUTTON_8"		: [GamepadControls.LB,						 0,	1],
								"BUTTON_9"		: [GamepadControls.RB,						 0,	1],
								"BUTTON_10"		: [GamepadControls.LT,						 0,	1],
								"BUTTON_11"		: [GamepadControls.RT,						 0,	1],
								"BUTTON_12"		: [GamepadControls.BACK,					 0,	1],
								"BUTTON_13"		: [GamepadControls.START,					 0,	1],
								"BUTTON_14"		: [GamepadControls.STICK_LEFT_PRESS,		 0,	1],
								"BUTTON_15"		: [GamepadControls.STICK_RIGHT_PRESS,		 0,	1],
								"BUTTON_16"		: [GamepadControls.DPAD_UP,					 0,	1],
								"BUTTON_17"		: [GamepadControls.DPAD_DOWN,				 0,	1],
								"BUTTON_18"		: [GamepadControls.DPAD_LEFT,				 0,	1],
								"BUTTON_19"		: [GamepadControls.DPAD_RIGHT,				 0,	1]
							},
							"keys" : [
							]
						}
					}
				},
				"ouya" : {
					"filters" : {
						"manufacturer"		: "Android Linux",
						"os"				: "Linux",
						"version"			: "AND"
					},
					"gamepads" : {
						"native" : {
							"filters" : {
								"name"			: "OUYA Game Controller"
							},
							"controls" : {
								"AXIS_0"		: [GamepadControls.STICK_LEFT_X,			-1,	1],
								"AXIS_1"		: [GamepadControls.STICK_LEFT_Y,			-1,	1],
								"AXIS_11"		: [GamepadControls.STICK_RIGHT_X,			-1,	1],
								"AXIS_14"		: [GamepadControls.STICK_RIGHT_Y,			-1,	1],
								"AXIS_17"		: [GamepadControls.LT,						 0,	1],
								"AXIS_18"		: [GamepadControls.RT,						 0,	1],
								"BUTTON_19"		: [GamepadControls.DPAD_UP,					 0,	1],
								"BUTTON_20"		: [GamepadControls.DPAD_DOWN,				 0,	1],
								"BUTTON_21"		: [GamepadControls.DPAD_LEFT,				 0,	1],
								"BUTTON_22"		: [GamepadControls.DPAD_RIGHT,				 0,	1],
								"BUTTON_96"		: [GamepadControls.ACTION_DOWN,				 0,	1],
								"BUTTON_97"		: [GamepadControls.ACTION_RIGHT,			 0,	1],
								"BUTTON_99"		: [GamepadControls.ACTION_LEFT,				 0,	1],
								"BUTTON_100"	: [GamepadControls.ACTION_UP,				 0,	1],
								"BUTTON_102"	: [GamepadControls.LB,						 0,	1],
								"BUTTON_103"	: [GamepadControls.RB,						 0,	1],
								"BUTTON_106"	: [GamepadControls.STICK_LEFT_PRESS,		 0,	1],
								"BUTTON_107"	: [GamepadControls.STICK_RIGHT_PRESS,		 0,	1]

								// Ignored:
								// "BUTTON_104"	: [GamepadControls.CONTROL_L2_DIGITAL,				 0,	1],
								// "BUTTON_105"	: [GamepadControls.CONTROL_R2_DIGITAL,				 0,	1],

								// Missing:
								// CONTROL_START (via keyboard though)
								// CONTROL_MENU
								// CONTROL_BACK
							},
							"keys" : [
								{
									// OUYA button
									"code"			: Keyboard.MENU,
									"location"		: KeyLocation.STANDARD,
									"id"			: GamepadControls.START
								}
							]
						},
						"ps3" : {
							"filters" : {
								"name"			: "Sony PLAYSTATION(R)3 Controller"
							},
							"controls" : {
								"AXIS_0"		: [GamepadControls.STICK_LEFT_X,			-1,	1],
								"AXIS_1"		: [GamepadControls.STICK_LEFT_Y,			-1,	1],
								"AXIS_11"		: [GamepadControls.STICK_RIGHT_X,			-1,	1],
								"AXIS_14"		: [GamepadControls.STICK_RIGHT_Y,			-1,	1],
								"AXIS_17"		: [GamepadControls.LT,						 0,	1],
								"AXIS_18"		: [GamepadControls.RT,						 0,	1],
								"AXIS_36"		: [GamepadControls.DPAD_UP,					 0,	1],
								"AXIS_37"		: [GamepadControls.DPAD_RIGHT,				 0,	1],
								"AXIS_38"		: [GamepadControls.DPAD_DOWN,				 0,	1],
								"AXIS_39"		: [GamepadControls.DPAD_LEFT,				 0,	1],
								"BUTTON_96"		: [GamepadControls.ACTION_DOWN,				 0,	1],
								"BUTTON_97"		: [GamepadControls.ACTION_RIGHT,			 0,	1],
								"BUTTON_99"		: [GamepadControls.ACTION_LEFT,				 0,	1],
								"BUTTON_100"	: [GamepadControls.ACTION_UP,				 0,	1],
								"BUTTON_102"	: [GamepadControls.LB,						 0,	1],
								"BUTTON_103"	: [GamepadControls.RB,						 0,	1],
								"BUTTON_106"	: [GamepadControls.STICK_LEFT_PRESS,		 0,	1],
								"BUTTON_107"	: [GamepadControls.STICK_RIGHT_PRESS,		 0,	1],
								"BUTTON_108"	: [GamepadControls.START,					 0,	1]

								// Ignored:
								// "BUTTON_19"		: [GamepadControls.CONTROL_DPAD_UP,					 0,	1],
								// "BUTTON_20"		: [GamepadControls.CONTROL_DPAD_DOWN,				 0,	1],
								// "BUTTON_21"		: [GamepadControls.CONTROL_DPAD_LEFT,				 0,	1],
								// "BUTTON_22"		: [GamepadControls.CONTROL_DPAD_RIGHT,				 0,	1],

								// Missing:
								// CONTROL_MENU (via keyboard though)
								// CONTROL_BACK (via keyboard though)
							},
							"keys" : [
								{
									// SELECT button
									"code"			: Keyboard.BACK,
									"location"		: KeyLocation.STANDARD,
									"id"			: GamepadControls.BACK
								},
								{
									// PS button
									"code"			: Keyboard.MENU,
									"location"		: KeyLocation.STANDARD,
									"id"			: GamepadControls.MENU
								}
							]
						},
						"xbox360" : {
							"filters" : {
								"name"			: "Microsoft X-Box 360 pad"
							},
							"controls" : {
								"AXIS_0"		: [GamepadControls.STICK_LEFT_X,			-1,	1],
								"AXIS_1"		: [GamepadControls.STICK_LEFT_Y,			-1,	1],
								"AXIS_11"		: [GamepadControls.STICK_RIGHT_X,			-1,	1],
								"AXIS_14"		: [GamepadControls.STICK_RIGHT_Y,			-1,	1],
								"AXIS_15"		: [[GamepadControls.DPAD_LEFT, 0, -1],	[GamepadControls.DPAD_RIGHT, 0, 1], 				 0,	1],
								"AXIS_16"		: [[GamepadControls.DPAD_UP, 0, -1],	[GamepadControls.DPAD_DOWN, 0, 1], 					 0,	1],
								"AXIS_17"		: [GamepadControls.LT,						 0,	1],
								"AXIS_18"		: [GamepadControls.RT,						 0,	1],
								"BUTTON_96"		: [GamepadControls.ACTION_DOWN,				 0,	1],
								"BUTTON_97"		: [GamepadControls.ACTION_RIGHT,			 0,	1],
								"BUTTON_99"		: [GamepadControls.ACTION_LEFT,				 0,	1],
								"BUTTON_100"	: [GamepadControls.ACTION_UP,				 0,	1],
								"BUTTON_102"	: [GamepadControls.LB,						 0,	1],
								"BUTTON_103"	: [GamepadControls.RB,						 0,	1],
								"BUTTON_106"	: [GamepadControls.STICK_LEFT_PRESS,		 0,	1],
								"BUTTON_107"	: [GamepadControls.STICK_RIGHT_PRESS,		 0,	1],
								"BUTTON_108"	: [GamepadControls.START,					 0,	1]

								// Ignored:
								// "BUTTON_19"		: [GamepadControls.CONTROL_DPAD_UP,					 0,	1],
								// "BUTTON_20"		: [GamepadControls.CONTROL_DPAD_DOWN,				 0,	1],
								// "BUTTON_21"		: [GamepadControls.CONTROL_DPAD_LEFT,				 0,	1],
								// "BUTTON_22"		: [GamepadControls.CONTROL_DPAD_RIGHT,				 0,	1],

								// Missing:
								// CONTROL_MENU (via keyboard though)
								// CONTROL_BACK (via keyboard though)
							},
							"keys" : [
								{
									// BACK button
									"code"			: Keyboard.BACK,
									"location"		: KeyLocation.STANDARD,
									"id"			: GamepadControls.BACK
								},
								{
									// XBOX button
									"code"			: Keyboard.MENU,
									"location"		: KeyLocation.STANDARD,
									"id"			: GamepadControls.MENU
								}
							]
						}
					}
				}
			};
		}

		// ================================================================================================================
		// CONSTRUCTOR ----------------------------------------------------------------------------------------------------

		public function KeyActionBinder() {
			alwaysPreventDefault = true;
			bindings = new Vector.<BindingInfo>();
			actionsActivations = {};

			_onActionActivated = new SimpleSignal();
			_onActionDeactivated = new SimpleSignal();
			_onSensitiveActionChanged = new SimpleSignal();

			start();
{'fraction_non_alphanumeric': 0.17701646664806028, 'fraction_numerical': 0.029025955902874687, 'mean_word_length': 2.270134610997034, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1684178', 'n_tokens_mistral': 6740, 'n_tokens_neox': 4800, 'n_words': 981}