InputHandler keystrokes

two things -



First have created my own AbstractBaseGame and BaseGame.

in doing so have written an input handler to push all of the show bounds/normals/lights into its own class - similar to KeyboardLookHandler where it uses events.

It makes the initsystem and update methods alot clearer. There is a fair bit of code, will post it up if anyone is interested. the guts are :-






import com.jme.input.InputHandler;
import com.jme.input.KeyInput;

public class DebugableInputHandler extends InputHandler{
   
   protected DebugActionable debugable;
   
   public DebugableInputHandler(DebugActionable debugable) {
      super();
      this.debugable = debugable;
      setKeys();
   }
   
   protected void setKeys() {
      addAction( new PauseAction(debugable ), "toggle_pause", KeyInput.KEY_P,true );      
      addAction( new ShowBoundsAction(debugable ), "toggle_bounds",KeyInput.KEY_B, true );   
      addAction( new NormalsAction(debugable ), "toggle_normals",KeyInput.KEY_N, true );
      addAction( new DepthAction(debugable ), "toggle_depth",KeyInput.KEY_F3, true );
      addAction( new WireAction(debugable ), "toggle_wire",KeyInput.KEY_T, true );
      addAction( new LightsAction(debugable ), "toggle_lights",KeyInput.KEY_L, true );
      addAction( new ScreenShotAction(debugable ), "screen_shot",KeyInput.KEY_F1, true );
      addAction( new CameraOutAction(debugable ), "camera_out",KeyInput.KEY_C, true );
      addAction( new QuitAction(debugable ), "exit",KeyInput.KEY_ESCAPE, true );
   }

}


public interface DebugActionable {
   
   public void togglePause();
   public void toggleBounds();
   public void toggleDepth();
   public void toggleLights();
   public void toggleNormals();
   public void toggleWire();   
   public void cameraOut();
   public void screenShot();
   public void finish();

}



Just let simplegame implement the DebugActionable interface and construct the DebugableInputHandler passing in simplegame

The other advantage is that it is easy to enable and disable.

Second point, on stepping through the InputHandler code - the system has to check each action trigger every frame - so the above debugable has 9 actions, keyboard look handler has 8 - thats 17 iterations each frame.

Has anyone got any reasons why the input handler cannot be redone to use a simple cache of actions that require invocation. The update method would only need to test if

If you use the new subcribing methods for key, mouse and joystick etc. input (with parameters device, key- and axisindex - not 'commands') you get exactly what you are asking for. Have a look into TestInputHandler or the Wiki for examples. The input handler was revamped (cvs version) to be event-based. The old commands are still in there to support keystokes with modifiers (ctrl, shift, alt etc.) - simply because nobody (meaning esp. me :)) has implemented that event-based yet…

Are there any concrete plans to add meta key (ctrl, shift, alt) checks in the event handling?

I could work around with some more actions triggered by RSHIFT, LSHIFT, etc. but I would prefer a more clean solution.

No plans like that… what about using KeyInput.get().isKeyDown( … ) ?

I'm wondering whether this would be reliable. What if I have some queued events and there were some with shift pressed and some without?

It won't be 'reliable'. But modifiers are missed when they are down less than a frame, only. I didn't have the need for modifiers in any game, yet

If you need them reliable (and maybe want other key states, too) I would suggest to keep track of them in the application (like you said).