Hello, I currently have this:
[java]package be.werner291.ORPG.client;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import java.util.concurrent.Callable;
public class InputHandler implements ActionListener{
InputManager inputManager;
public boolean left = false;
public boolean right = false;
public boolean forward = false;
public boolean back = false;
public InputHandler() {
inputManager = ORPGClient.programInstance.getInputManager();
inputManager.addMapping(“A”, new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(“B”, new KeyTrigger(KeyInput.KEY_B));
inputManager.addMapping(“C”, new KeyTrigger(KeyInput.KEY_C));
inputManager.addMapping(“D”, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(“E”, new KeyTrigger(KeyInput.KEY_E));
inputManager.addMapping(“F”, new KeyTrigger(KeyInput.KEY_F));
inputManager.addMapping(“G”, new KeyTrigger(KeyInput.KEY_G));
inputManager.addMapping(“H”, new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping(“I”, new KeyTrigger(KeyInput.KEY_I));
inputManager.addMapping(“J”, new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping(“K”, new KeyTrigger(KeyInput.KEY_K));
inputManager.addMapping(“L”, new KeyTrigger(KeyInput.KEY_L));
inputManager.addMapping(“M”, new KeyTrigger(KeyInput.KEY_M));
inputManager.addMapping(“N”, new KeyTrigger(KeyInput.KEY_N));
inputManager.addMapping(“O”, new KeyTrigger(KeyInput.KEY_O));
inputManager.addMapping(“P”, new KeyTrigger(KeyInput.KEY_P));
inputManager.addMapping(“Q”, new KeyTrigger(KeyInput.KEY_Q));
inputManager.addMapping(“R”, new KeyTrigger(KeyInput.KEY_R));
inputManager.addMapping(“S”, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(“T”, new KeyTrigger(KeyInput.KEY_T));
inputManager.addMapping(“U”, new KeyTrigger(KeyInput.KEY_U));
inputManager.addMapping(“V”, new KeyTrigger(KeyInput.KEY_V));
inputManager.addMapping(“W”, new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping(“X”, new KeyTrigger(KeyInput.KEY_X));
inputManager.addMapping(“Y”, new KeyTrigger(KeyInput.KEY_Y));
inputManager.addMapping(“Z”, new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping(“Enter”, new KeyTrigger(KeyInput.KEY_RETURN));
inputManager.deleteMapping(“SIMPLEAPP_Exit”);
inputManager.addMapping(“Escape”, new KeyTrigger(KeyInput.KEY_ESCAPE));
inputManager.addListener(this, “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”,
“J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”,
“X”, “Y”, “Z”, “Enter”, “Escape”);
}
public void onAction(final String binding, final boolean value, final float tpf) {
ORPGClient.programInstance.enqueue(new Callable<Object>(){
public Object call() throws Exception {
if (ORPGClient.programInstance.chatmode == false){
if (binding.equals(“A”)) {
if (value) { left = true; } else { left = false; }
} else if (binding.equals(“D”)) {
if (value) { right = true; } else { right = false; }
} else if (binding.equals(“W”)) {
if (value) { forward = true; } else { forward = false; }
} else if (binding.equals(“S”)) {
if (value) { back = true; } else { back = false; }
} else if (binding.equals(“C”)&&(value == true)){
ORPGClient.programInstance.chatmode = true;
ORPGClient.programInstance.getChatManager().startChat();
} else if (binding.equals(“Escape”)&&(value == true)){
ORPGClient.programInstance.stop();
}
} else {
if (binding.equals(“Enter”)&&(value == true)){
ORPGClient.programInstance.chatmode = false;
ORPGClient.programInstance.getChatManager().sendChat();
} else if (binding.equals(“Escape”)&&(value == true)){
ORPGClient.programInstance.chatmode = false;
ORPGClient.programInstance.getChatManager().cancelChat();
} else if (value == true) ORPGClient.programInstance.getChatManager().type(binding);
}
return null;
}
});
}
}[/java]
I guess that for simple controls (movement, jumping, etc…) this would be ok.
But what if I want to catch any ASCII character that is being typed? I could, off course, add a mapping and a listener for every character in the entire ASCII, but isn’t there a better solution?
What i’m talking about: [java]ORPGClient.programInstance.getChatManager().type(binding);[/java]
This function is supposed to give a string (i could change it to a character) containing a single character to the chat manager so it can add the character to the current chat line being composed.
I think this is what you are looking for http://hub.jmonkeyengine.org/groups/general-2/forum/topic/adding-input-commands-when-engine-is-running-and-addig-keyboard-combinations/.
If you want to catch all input then you really can’t do better than the RawInputListener. It’s whole point is to catch all input.
RawInputListener looks like exactly what I need.
Just one last question: How do I make it start listening?
EDIT: Found it. Thanks for the help!
Just add it to the input manager :P. I did an example on the link above.