Hi ,its a noob question ,but i cant finde a way to get keys thta are pressed. I have both listeners and they creates event’s but i dont want listeners to start action.
What i want i to have update that each second check which keys are pressed, soo basically i cant get access to where are stored data on pressed keys.
My main class extends SimpleApplication and have both listeners ,as on f1 guide ,but i cant finde a way to see keys pressed list or alse .
I know i could create my own data base ,but if there is one allready …
When you get the pressed event, set a flag.
When you get a released event, unset the flag.
That’s where the information will be stored. It isn’t anywhere else.
Yep. That’s it.
I use a InputState.
'…
public InputState(InputManager inputManager, Node controlled, SimpleApplication app){
this.inputManager = inputManager;
this.controlled = controlled;
this.app = (MyApp)app;
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (MyGame)app;//redundant
//TODO: initialize your AppState, e.g. attach controllables to rootNode
inputManager.setCursorVisible(true);
initKeys();
initMouse();
}
@Override
public void onAction(String action, boolean isPressed, int modifier, float tpf){
if(action.equals("Exit") && isPressed){
System.exit(0);
}
else if (action.equals("YawRight"){
controlled.yawRight(action, isPressed){
}
}
//in ControllableControl
public Void yawRight(String action, boolean isPressed){
yawRight = isPressed;
}
public void controlUpdate(float tpf){
if (yawLeft){
inputVector = new Vector3f(0f, rotationThrust[rotationThrustIndex], 0f);
torqueThrust = torqueThrust.add(inputVector);
input = true;
}
Thanks for ansewrs