Problem with custom inputmanager with swing

Hi,



I have got exactly the same problem. I use something like…


public class MyClass extends JMECanvasImplementor {

    static {    
        KeyInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);
    }

    ....
    private InputHandler inputHandler;
    ....

    @Override
    public void doSetup() {
        if (!setup) {
        ...
            inputHandler = new InputHandler();
            KeyInputAction keyInputAction = new KeyInputAction() {

                public void performAction(InputActionEvent evt) {
                    System.out.println("This should be printed if space is pressed, but isn't. Why?");
                }
            };

            KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
            keyboard.set("space", KeyInput.KEY_SPACE);
            inputHandler.addAction(keyInputAction, "space", false);
            inputHandler.setEnabled(true);
        ...
        }
    }
  
    @Override
    public void doUpdate() {
        if (setup && rootNode != null) {
            ...
            inputHandler.update(tpf);
            ...
        }
    }
}



No action is ever performed in AWT / Swing

Hi,



I have solved the problem. The trick is to get the KeyListener from the KeyInput method and register it in the canvas!!!


public class MyClass extends JMECanvasImplementor {

    static {    
        KeyInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);
    }

    ....
    private InputHandler inputHandler;
    ....

    public MyClass{
        myCanvas.addKeyListener((KeyListener)KeyInput.get());
    }


    @Override
    public void doSetup() {
        if (!setup) {
        ...
            inputHandler = new InputHandler();
            KeyInputAction keyInputAction = new KeyInputAction() {

                public void performAction(InputActionEvent evt) {
                    System.out.println("This should be printed if space is pressed, but isn't. Why?");
                }
            };

            KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
            keyboard.set("space", KeyInput.KEY_SPACE);
            inputHandler.addAction(keyInputAction, "space", false);
            inputHandler.setEnabled(true);
        ...
        }
    }
  
    @Override
    public void doUpdate() {
        if (setup && rootNode != null) {
            ...
            inputHandler.update(tpf);
            ...
        }
    }
}



JME rules  :D