How to generate key events?

I am using a standard Input manager and key listener like:

[java]



inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));



inputManager.addListener(this, "Left");



[/java]



My question is, how can i trigger a key from Code? I want to fire this key trigger from somewhere in the code.



regards



chris

Wyh trigger the key manually? put the logic in a method that happens on keyevent, and call that directly

I want to abuse the key event queue :slight_smile: i think this must be possible, i also looked in the source code but no idea yet…

I think InputManager specifically disallows this by making sure the queue is not modified except during event handling. I think is probably ok… after all, it’s easy enough just to call your listeners yourself.



However, I did want to forward joystick events to nifty as keys (like up/down) so there was a method added on NiftyDisplay that lets you simulate key events sent to nifty. Depending on your use-case (and since this is in the GUI section), I thought I would mention it.

I would also imagine you might want nifty (or your own HUD) to emulate joystick events for your Android game. In that case you may need to wrap the context … its not easy I guess.

@Momoko_Fan said:
I would also imagine you might want nifty (or your own HUD) to emulate joystick events for your Android game. In that case you may need to wrap the context .. its not easy I guess.


In that case, the UI can just call the analog listeners, etc. directly. No reason to involve InputManager since there is no real input.