NiftyGUI not consuming events before other RawInputListener

Hello,

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.

What order do you initialize nifty versus adding your raw listener?

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.)

It’s done in NiftyJmeDisplay.initialize()

(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.

Hi,

My IDE (jme3 sdk) is having problems navigating source so (I posted about it here: http://hub.jmonkeyengine.org/forum/topic/problems-navigating-jme3-sources-with-jme3-sdk/)
I was only able to browse the source on github and also found the initialize method shortly after my last edit.

I missed the fact that it is in a SceneProcessor though.
I am pretty sure that I can find the solution now. Thank you for your help :slight_smile:

I will post here again in the next days if I do not find the solution.

@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.

How can I mark this as resolved?