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());
app.getGuiViewPort().addProcessor(niftyDisplay);[/java]
(I system.out the pressed keys in my RawInputListener and can see the triggered keys while writing in a nifty textbox.)
(source code is always only a click away, here or in the IDE.)
It’s a SceneProcessor so initialized during render, I guess… ie: after update is run, render is run. You could wrap your listener in a SceneProcessor also and add it after.
@pspeed said:
It's done in NiftyJmeDisplay.initialize()
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-niftygui/src/main/java/com/jme3/niftygui/NiftyJmeDisplay.java#L190
(source code is always only a click away, here or in the IDE.)
It’s a SceneProcessor so initialized during render, I guess… ie: after update is run, render is run. You could wrap your listener in a SceneProcessor also and add it after.
Thank you! Wrapping my listener in a SceneProcessor worked perfectly!
I also learned more about jMonkey reading about the SceneProcessors and RenderManager.