We are building an input system with customizable key mappings.
For this reason we chose the RawInputListener, because we can store KeyEventCodes (KeyCode + Modifier flags for CTRL and SHIFT) in a map.
Here we map one KeyEventCode to a List of Events which are triggered via Guavas Eventbus. (Very simple and effective)
Everything works brilliant and we can map actions to “CTRL+SHIFT+I” at runtime for example.
Our only Problem: Nifty will not consume events before our RawInputListener does.
Did Nifty not have it’s own RawInputListener?
We cannot use Action and Analog Listeners, because we do not want to add a mapping for every single key.
Also, we will have very ugly code with CTRL and SHIFT modifiers.
UPDATE: When I delay the initialization of my rawInputListener with a timer, it works.
How do I properly wait for Niftys initialization? Simply calling my initInputListener() after initNifty() doesn’t suffice.
I call initInputListener() and initNifty() in my application initialization.
The order in which I call them does not make a difference.
Can this be a threading issue? When exactly does nifty attach its raw listener to the inputManager?
code for initInputListener():
[java]inputManager.addRawInputListener(new InputListener()); //InputListener is the RawInputListener[/java]
code for initNifty():
[java]NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
(I system.out the pressed keys in my RawInputListener and can see the triggered keys while writing in a nifty textbox.)