InputManager with modifiers (Shift, Control, etc.)

I don’t believe that the current InputManager handles modifiers (Shift, Control, Alt, Meta). I hacked into and added that capability - once for all. For example, you can use numpad3 and numpad4, for left and right strafing and use Control numpad3 and Control numpad4 for left and right turn. The old interface is still intact. The change required me to add a field to the (private) Mapping class and then test it before calling onAction(). Also, while testing I discovered that if you let up a modifier key with another key pressed, it doesn’t turn off when you let the key up (because the modifiers have changed). Ergo, I added a list to keep track of the current actions and send them a isPressed=false when you change the modifiers. If you’re rotating and you let the Control key up, it will turn off rotating thrust (not rotating momentum).

It works on three levels.
You can 1) use it without modifiers like the old interface (only calling onAction(String, boolean, float)). Or you can 2) use it with basic modifiers, Shift, Control, etc., (onAction(String, boolean, int, float)) or you can 3) use it to check individule modifier keys like LeftShift or RightShift, LeftControl or RightControl. You can use the modifier keys with the joystick, mouse, and tablet, too.

To try it out or use it, I have an InputManagerModifiersTest.

  1. Make a new project, i.e. \Modifiers
  2. Copy the sources from C:\Program Files\jmonkeyplatform\jmonkeyplatform\libs\ into your \Modifiers project/s, src directory. Put my into the com.jme3.input directory and then open and compile. You’ll have to modify all the classes that have onAction() in them. The compiler will tell you what files to fix. See below for a list.
  3. Make a new folder in a JME\libs\JME3-core.dir.
    Copy com, Common, Interface, Jme3tools into JME\libs\JME-core.dir. Then in your other projects, refer to JME\libs\JME3-core.dir. If you set the setEcho(true), it will print debug info and show you what it’s thinking. If you have menus and you hit the Alt key, you may have to hit Alt-Esc or Alt-Tab.

I have everything on Github.

Files to be modified

(I hope that this isn’t too over the top for the developers. If it is, all you can do is cancel my account…) :wink:

Alternately, you can use Lemur’s InputMapper which supports key combos, multiple mappings, etc… without hacking into JME’s low level InputManager.

InputMapper even lets you treat keys like axes and axes like keys. It’s very flexible. (There has been talk of rolling it right into JME.)

You can easily use it without using the rest of Lemur, just include the jars and only use the InputMapper related classes.

More information on Lemur here:

And InputMapper specifically here:

Here is an example (from the Lemur Gem on camera movement) for setting up InputMapper default mappings for camera movement that links joystick axies, mouse look, keys, etc. to the same sets of function IDs:

But for example, if I wanted forward movement to be shift W instead of just W… then I’d change: F_MOVE, KeyInput.KEY_W );
To: F_MOVE, KeyInput.KEY_LSHIFT, KeyInput.KEY_W );

Ok. I searched for “InputManager modifiers” and such and didn’t come up with anything. I’ll look into it.