Home

Awesome

input2action

haxe library to easy handle configuration and bingings of keyboard/gamepad-buttons to haxe-calls

Features

Dependencies

Installation

haxelib install input2action

or use the latest developement version from github:

haxelib git input2action https://github.com/maitag/input2action.git

Synopsis

// bindings for keyboard and gamepad:
var actionConfig:ActionConfig = [
	{	action: "moveLeft",
		keyboard: [ KeyCode.A, KeyCode.LEFT],
		gamepad:  [ GamepadButton.DPAD_LEFT ]
	},
	{	action: "moveRight",
		keyboard: [ KeyCode.D, KeyCode.RIGHT],
		gamepad:  [ GamepadButton.DPAD_RIGHT ]
	},
	{	action: "fire",
		keyboard: [ KeyCode.LEFT_CTRL, KeyCode.RIGHT_CTRL ],
		gamepad:  [ GamepadButton.LEFT_SHOULDER ]
	}
];

// show how it would look into json-format
trace(actionConfig.toJson);


// contains the actions and mappings to functionpointers
var actionMap:ActionMap = [
	"moveLeft"  => { action:moveLeft , up:true },
	"moveRight" => { action:moveRight, up:true },
	"fire"  => { action:fire }		
];


// functions to call
function moveLeft(isDown:Bool, param:Int) {
	trace('moveLeft - ${(isDown) ? "DOWN" : "UP"}, param:$param');
}

function moveRight(isDown:Bool, param:Int) {
	trace('moveRight - ${(isDown) ? "DOWN" : "UP"}, param:$param');
}

function fire(isDown:Bool, param:Int) {
	trace('fire - ${(isDown) ? "DOWN" : "UP"}, param:$param');
}


// init with the lime window object to set up keyboard up/down handlers
var input2Action = new Input2Action(window);

// set keyboard bindings
var keyboardAction = new KeyboardAction(actionConfig, actionMap);

// add it to input2action
input2Action.addKeyboard(keyboardAction);

// start
input2Action.enable();

Please look into the samples-folder to see all options for different usecases.

TODO