Problems with keyboard bound keys

I’m going to create a command like this to bind the TestBuiling method to the A key of the keyboard, but I’m having a problem how do I convert the A String type in the command line to an int type in the KeyInput?

You can’t, really. Not easily.

If you want to let players bind keys to functions then you need to go into some kind of “listening mode” where you record the next key event from a RawInputListener.

If you want to let them manually bind keys then it has to be based on an int… or you will have to build a table mapping key names to ints. Basically, the reverse of:

1 Like

Okay thanks for the reply

The difficulty is that conversion between scan codes and key names depends on keyboard layout. There are many dozens of different keyboard layouts.

If you’re using LWJGL v3 (in other words, jme3-lwjgl3 not jme3-lwjgl) you can use InputManager.getKeyName() to obtain the key name for a specified scan code. You can invert this function easily, but that will break if the user changes the keyboard layout while your app is running.

1 Like

For the time being, let’s do this.

I’ll try to re-do it this way after a while.

Okay thanks for the reply