KeyBindingManager vs. GameControl -- What's the difference?

Hi everyone,

just discovered jMonkeyEngine some days ago, it’s been a bit rough (Wiki is not exhaustive enough for newcomers, hopefully I’ll be able to contribute there later), but all in all I’m very impressed.

So, my question.

I’ve been looking at the example found here, which has helped me greatly wrt. understanding GameStates.

I’m a bit baffled though, but the use of both KeyBindingManager and more vanilla GameControl, as seen here:

 * Our InputGameState.
 * For comparison we use two different Input systems.
 * To Enable/disable the TextGamestate (F1) we use the GamecontrolSystem.
 * For the other Keys, the easier to use KeyBindingManager is used.
public class InputGameState extends BasicGameState {
     * constructor, creates the Inputhandler and actions to listen for.
    public InputGameState(String name) {
        // the GameControl System:
        // 1. create GameControlManager, needed to create controls from
        GameControlManager manager = new GameControlManager();
        // 2. create a GameControl as input for the Controller later
        GameControl textTogglecontrol = manager.addControl("toggle_text");
        // 3. add a Key Binding to the gameControl (F1)
        textTogglecontrol.addBinding(new KeyboardBinding(KeyInput.KEY_F1));
        // 4. create a Controller, which gets the InputValues from the GameControl
        ActionChangeController textToggleAction = new ActionChangeController(textTogglecontrol, new ControlChangeListener() {
            public void changed(GameControl control, float oldValue,
                    float newValue, float time) {
                // toggle TextGameState active/inactive
                // get the GameState
                GameState textGS = GameStateManager.getInstance().getChild("text");
                // invert the GameStates active flag
        // 5. add the controller to a node, so that it gets updated every update cycle.
        // adding new actions to the KeybindingManager
        KeyBindingManager.getKeyBindingManager().add("toggle_3d", KeyInput.KEY_F2);
        KeyBindingManager.getKeyBindingManager().add("toggle_stat", KeyInput.KEY_F3);
        KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
     * Check if the a Key that we defined previously, has been pressed and execute the according action
    public void update(float tpf) {
        // check if F2 has been pressed and toggle the 3D Gamestate
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("toggle_3d", false)) {
            // invert the active flag of the 3D GameState
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("toggle_stat", false)) {
            // invert the active flag of the 3D GameState
        // check if ESC has been pressed, exit the application if needed
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)) {
            System.out.println("Good Bye");

What are the differences between using KeyBindingManager like seen with F2, F3 and F4 in this example, compared to just calling this? Are there really two different systems for doing this, or is one of them a wrapper for the other?

manager.addControl("toggle_3d").addBinding(new KeyboardBinding(KeyInput.KEY_F2));

They are pretty much two completely different systems.

You can decide yourself what fits your needs better.

In small tests its often easier to use the KeyBindingManager, while in games (well one game in my case …  :slight_smile: ) i tend to use GameControls.