How to detect left control + s, namely, a combination of KeyInputs?

Hi,

Q: how do I set up detecting, say, left ctrl + s, for saving a game and, say, left ctrl + p, for pausing a game, etc.

I read http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_input_system but still can’t figure out how to tweak ActionListener
into detecting a combination of KeyInputs.

Can someone help?

Thanks much,

mk7

JME doesn’t do this for you.

But if you use Lemur’s InputMapper you can do it pretty easily.

http://jmonkeyengine-contributions.github.io/Lemur/

Even if you don’t want to use the whole GUI, you can use InputMapper on its own. All of the parts of Lemur are modular.

Hello,

You need to intercept pressing and releasing KEY_LCONTROL and save this condition. When you press the command buttons (“s” or “p”) to check the saved status.

Or use Lemur’s InputMapper which lets you do this without the extra code.

FunctionId myFunc = new FunctionId("Do Something");
inputMapper.map(myFunc, KeyInput.KEY_LCONTROL, KeyInput.KEY_S);
...
// Add a listener or delegate to a method or... whatever
inputMapper.addStateListener(myListener, myFunc);
..or...
inputMapper.addDelegate(myFunc, this, "doSomething");

Done.

http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/input/InputMapper.html

How do I set up the StateListener or Delegate ?

It’s more complicated than I thought.

I tried to understand some examples out there.

I think I have to create a class, say calling it InputCommands, and implements StateFunctionListener.

Then inside that class, I will have valueChanged()…

I’m confused. do I need to do stateManager.attach(new InputCommands()) ?

thx for help!

Chances are you may already have a delegate. A delegate in this case is just “any of your classes” that happen to have “any of your methods that might do the thing you want doing”. Since I don’t know anything at all about how your code is setup it’s hard for me to comment more specifically.

The delegate is the easiest way because it probably uses code you already have.

Here is an example of using a delegate method that you might already have:
https://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/examples/LemurGems/src/gems/CameraToggleState.java

(See the toggleCamera() method and how it’s added.)

Here is an example using actual listeners… which are implemented in the standard way all Java listeners are implemented:
https://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/examples/LemurGems/src/gems/CameraMovementState.java

In this case, I had the app state itself implement the listeners. It could have just as easily been an inner class or an anonymous inner class. (If you don’t know what an anonymous inner class is then google is your friend as you have some basic Java to beef up on which is probably off topic here.)

Edit: and if you are curious, those come from Lemur Gems #1: Lemur Gems #1 : InputMapper based camera movement