KeyBindingManager improvemnt

Hello.

I think KeyBindingManager could use methodes like



String[] getCommandsAtKey(int keyInputValue) … which will return all commands assigned to key

void removeAllCommandsAt(int keyInputValue) … which will remove all commands association to key

…plus, if needed, variations to get/remove only first value



I specially needed last one, where I was building my test game on SimpleGame, and wanted to re-assign left, right, up and down arrows for something of my own. I could not do it easily of course since only remove method takes command as an argument, and therefore I needed to know exact commands to remove them. Finally I had a peek to source code of SimpleGame, tracking input initialization to KeyboardLookHandler to see the commands.

On the other hand I'm noob at jme and this maybe isn't needed at all since in final game you will define all bindings yourself, …but again, what if someone extends it? Anyway just a suggestion, you are the devs, I'll leave it to you.

You can override the existing key bindings if you want

e.g.



KeyBindingManager.getKeyBindingManager().set( "screen_shot",

                KeyInput.KEY_ESCAPE );



will give you a screenshot when you hit the escape key.



When I got started with JME… ok, well, not when I got started but later on after I got started… I simply took BaseSimpleGame and removed the key settings.



After that, DF got me hooked on GameStates after reading his tutorial and now I use the GameSettings and apply my key settings that way.



It's a matter of preference, but for speed I took BaseSimpleGame pulled out the parts I didn't want and renamed it locally, then I copied SimpleGame and renamed it locally… THEN after all that I made my app extend the new SimpleGame that I had created.



If you just want to do something different with the key then using the KeyBindingManager settings above will do the trick as well.



you could also do

KeyBindingManager.getKeyBindingManager().remove( "toggle_pause");

KeyBindingManager.getKeyBindingManager().remove( "step");

KeyBindingManager.getKeyBindingManager().remove( "toggle_wire");

KeyBindingManager.getKeyBindingManager().remove( "toggle_lights");

KeyBindingManager.getKeyBindingManager().remove( "toggle_bounds");

KeyBindingManager.getKeyBindingManager().remove( "toggle_normals");

KeyBindingManager.getKeyBindingManager().remove( "camera_out");

KeyBindingManager.getKeyBindingManager().remove( "screen_shot");

KeyBindingManager.getKeyBindingManager().remove( "exit");

KeyBindingManager.getKeyBindingManager().remove( "parallel_projection");

KeyBindingManager.getKeyBindingManager().remove( "toggle_depth");

KeyBindingManager.getKeyBindingManager().remove("mem_report");



that seems to do the trick as well.



Just remember that doing it this way, I've included "exit" so you won't be able to exit without closing the window down another way.



thx,



timo

hmmm,

"javadoc" wrote:
public void set(java.lang.String command, int keyCode)

    set sets the command to the given keycode overriding any previous keycodes previously set for the same command.

doesn't this mean that you only remove same command binded before, but not other commands binded to the keycode?
Example, if you bind "action" to key_esc, and "action2" to key_enter, when you do .set("action", key_enter) you remove "action" from key_esc, but "action2" stays on key_enter.
So you still can't get rid of previous actions on some keycode.

Thank you for your input, it is very usefull, but the point isn't about me learning what to start with, but how to improve KeyBindingManager

edit: tag stuff

you are correct.



My intention wasn't to downplay the suggestion, simply suggest other options for those that want to know as well.

so no one from development answered… is this problem that suggestion addresses something solvable or what?

I would answer, but I don't use KeyBindingManager, I use GameControlManager instead.  :stuck_out_tongue:

darkfrog said:

I would answer, but I don't use KeyBindingManager, I use GameControlManager instead.  :P


Author:
    Matthew D. Hicks

.... so this is why javadoc on GameControlManager is empty :)
anyway, is what I mentioned solved in GCM? Are there tutorials for GCM?
Kova said:

Author:
    Matthew D. Hicks


Who's that?  :roll:

If you look at TestSwingControlEditor it goes well beyond just the basics of GameControlManager and shows how to create a control editor that you can then use:
https://jme.dev.java.net/source/browse/jme/src/jmetest/input/controls/TestSwingControlEditor.java?view=markup

It's actually quite easy to understand conceptually, you don't have to use the editor to assign keys, you can do it programmatically.  I do need to write a tutorial on how to use this, but it's relatively straight-forward and will hopefully resolve all your problems. :)

Thank you.

I'm curious about one more thing… is this meant to replace KeyBindingManager?

good thing one of our goals for 1.0 is to make javadocs for everything :slight_smile:

Sort of my unofficial intent, but people have to try it and decide they like it before that can happen. :slight_smile:


MrCoder said:

good thing one of our goals for 1.0 is to make javadocs for everything :)


This is true. :)