Trying to disable user input have problem in lemur

I need to disable and enable user input but when I tried to disable user input (mouse and keyboard) by using setting.setUseInput(false); it throws this exception:

java.lang.NullPointerException at com.simsilica.lemur.event.BasePickState.onEnable( at at at at at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop( at com.jme3.system.lwjgl.LwjglDisplay.runLoop( at at

The approach you are using means you have to reset the whole JME context every time you want to enable/disable all input. Essentially, totally destroy InputManager when you disable, totally recreate InputManager when you enable.

…that’s probably not what you want.

Can you explain what you are actually trying to do?

1 Like

I have a lemur container that will cover all the screen, and a progress bar in it to show the loading of the model’s progress. I need to disable keyboard because of some key shortcut. and also I need to have a mouse pointer but it must have no event.

The popup state will handle mouse clicks for you.

If you do all of your mapping through Lemur’s InputMapper then you can manage activation groups which is the normal way. (Usually you don’t really want to disable ALL input… just the ones that makes sense… or rather, you only want to be activating the valid ones in the first place.)

If you really must intercept all key events then you could temporarily add a key listener to the KeyInterceptState that sets them all to consumed. That’s what the text fields to do make sure they typed keys don’t go to regular events.

Really, if you are using JME’s input manager at all and you already have Lemur then you are doing things the hard way… because JME’s input manager has kind of a crappy API. If you are using Lemur’s InputMapper then the ‘in game’ keys should already be mapped to a group that is only activated when the game is running.

…then no problems.

Edit: Note: this seems like it is recreating what the popup state will already do for you. There are examples in the lemur demo.

1 Like

Salient parts of the pop-up demo, here:

    protected void createColoredModalPopup() {        
        Panel popup = createPopup(true);
        // Create a random color.
        float r = (float)(Math.random() * 0.75 + 0.25);
        float g = (float)(Math.random() * 0.75 + 0.25);
        float b = (float)(Math.random() * 0.75 + 0.25);
        ColorRGBA c = new ColorRGBA(r, g, b, 0.5f);
        getState(PopupState.class).showPopup(popup, PopupState.ClickMode.Consume, closeCommand, c);

And some of that is optional.

1 Like

thank you for the answers.
It solved by putting the screen Container on top of other GUI elements by setting z Position=1000.
and I added a new MouseListener to it to Consume all mouse event that it received.

Which is precisely what the PopupState would already do for you if you ever wanted to clean up your code.

1 Like