[SOLVED] Mapping a trigger

This runs without errors for me, too. The console output is:

mapped=true

I’ve managed to achieve what I set out to do. Found a few issues along the way which is nice.

So basically you define actions (accelerate, etc) and some default bindings. You can add bindings by pressing them - as you would expect to do in a game. I havent done loading/saving yet or rejecting binding the same key to different actions, but this is basically what I was after. It doesn’t care about LWJGL2/3 issues - it just takes the triggers you give it and responds with an event when the trigger is activated.

InputBinder.initialize(this);

// these are the actions we want to use in our game.
// We'll also set some default keybindings, but we don't have to.
InputBinder.getInstance().bindMapping("Accelerate", new KeyTrigger(KeyInput.KEY_W), new KeyTrigger(KeyInput.KEY_Q)); // multiple triggers.
InputBinder.getInstance().bindMapping("Brake", new KeyTrigger(KeyInput.KEY_S));
InputBinder.getInstance().bindMapping("Steer Left", new KeyTrigger(KeyInput.KEY_A));
InputBinder.getInstance().bindMapping("Steer Right", new KeyTrigger(KeyInput.KEY_D));
InputBinder.getInstance().addMapping("Start Vehicle"); // no mapping (to test null mapping).

I’ll integrate it into my vehicle game first to see how well the code works and probably push it to github/jcenter if it becomes useful.

Thanks everyone for all the help :slight_smile:

2 Likes