Rebinding up and down keys

I want to rebind up and down fly keys from q and z to space for up and shift for down. The problem is that I don’t know what is the mapping name for up and for down.

To delete the input I would use:
inputManager.deleteMapping(""/Mapping name goes in there/);

But how to add new binding then? That’s also a thing I would be pleased if someone helped me with.

Now after a bit of thinking, I figured out that it would be best to just clear all keys and try implementing flying myself… Although I still think that it would be the best just to rebind those keys if that is even possible.

You can add a new mapping though

inputManager.addMapping("blabla", new KeyTrigger(KeyInput.KEY_SPACE);

this rebinds the “blabla” mapping to the space key

Yes, but I don’t know the default binding names…

And that, my friend, is the beauty of open source

from my jme3_ext (lib available on github, bintray)

public class SetupHelpers {
    static public void disableDefaults(SimpleApplication app) {
        app.enqueue(() -> {
            AppStateManager stateManager = app.getStateManager();
            return true;

Thans guys!! That is excactly what I wanted! :smile:

After finding this piece fo code in

    // keyboard only WASD for movement and WZ for rise/lower height
    inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_Q));
    inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_Z));

I typed this into my simpleInitApp():


But when I run my app, it makes no effect and I get this in the console:

feb 03, 2015 3:21:20 PM com.jme3.input.InputManager deleteMapping
WARNING: Cannot find mapping to be removed, skipping: FLYCAM_Rise
feb 03, 2015 3:21:20 PM com.jme3.input.InputManager deleteMapping
WARNING: Cannot find mapping to be removed, skipping: FLYCAM_Lower

Help anyone?

it’s because you remove it too early (before the binding is done). it’s why I suggest you to use enqueue, so it’s be done once in next update(tpf).

Thanks, that fixed it. Now it’s working correctly. :smiley:

in simpleInit the FlyCamAppState might not be initialised, so the mapping doesn’t exist yet.

you can either remove it once in the simpleUpdate but that’s a bit ugly.
Or create your own appState that does the work :

Create an appState that extends FlyCamAppState

just implements the initialize method like this

public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        //remove old mapping , create the new ones

then in the simple init do

stateManager.attach(new MyFlyCamAppState());
1 Like

Or that :stuck_out_tongue:

Just for anyone who gets this problem again, this is how I did it:

public void simpleUpdate(float tpf) {
    if (!deleted){
        inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_SPACE));
        inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_LSHIFT));
        inputManager.addListener(flyCam, "FLYCAM_Rise");
        inputManager.addListener(flyCam, "FLYCAM_Lower");
        deleted = true;

Where deleted is an instance variable which is set to false by default.