Menu button does not respond when using nifty

Hi,

I got a screen interface for the user, and it will always be some sort of nifty window up when running my game.

Problem is, it is perfectly impossible to know when the menu button is pressed.

http://hub.jmonkeyengine.org/groups/android/forum/topic/capturing-the-menu-key-in-android-activity/ does not work for me.



Just overriding the ontouch in the activity doesn’t work either, it doesn’t even fire.



Doing this:

[java]InputListerner il = new InputListerner();

InputManager inputManager = MainGame.getInput();



inputManager.addMapping(“menu”, new TouchTrigger(TouchInput.KEYCODE_MENU));

inputManager.addListener(il, “menu”);[/java]

[java]public void onAction(String binding, boolean value, float tpf) {

System.out.println("BINDING: “+binding+” value: “+value+” tpf: "+tpf);[/java]

does not execute either.



onCreateOptionsMenu and onTouchEvent never fires aswell…

So how am I suppose to get the menu button when having a fullscreen nifty up and running?

Do you click into the scene before? It could be the same issue that I noticed lately, that after clicking into the scene no input events are registered for anything inside a nifty window :frowning:

Nifty on android needs mouseEventsEnabled = true in the main activity, It’s the default value, but make sure you don’t override it.



@enum this issue is on android or on desktop, or both?

I have no android device to test it with :frowning:

If you have android specific views in addition to the surfaceview, the surfaceview will not recieve the touch events if one of the other android views has the focus. Try touching the surfaceview and then see if the events start registering. I use the following and it works fine.



[java]

inputManager.addMapping(TOUCH_MENU,

new TouchTrigger(TouchInput.KEYCODE_MENU),

new KeyTrigger(KeyInput.KEY_PERIOD)

);

inputManager.addListener(this, TOUCH_MENU);



inputManager.addMapping(TOUCH_BACK,

new TouchTrigger(TouchInput.KEYCODE_BACK),

new KeyTrigger(KeyInput.KEY_COMMA)

);

inputManager.addListener(this, TOUCH_BACK);



[/java]



[java]

public void onAction(String name, boolean isPressed, float tpf) {

logger.log(Level.INFO, "Action Event: {0}, {1}, {2}",

new Object[]{name, isPressed, tpf});

if (name.equals(TOUCH_MENU) && !isPressed) {

showSettingsScreen();

}

if (name.equals(TOUCH_BACK) && !isPressed) {

showPrevScreen();

}



}



[/java]



[java]

public void onTouch(String name, TouchEvent event, float tpf) {

logger.log(Level.INFO, "Touch Event: {0}, {1}, {2}",

new Object[]{name, event.getType(), tpf});



if (name.equals(TOUCH_MENU) && event.getType() == TouchEvent.Type.KEY_UP) {

showSettingsScreen();

}

if (name.equals(TOUCH_BACK) && event.getType() == TouchEvent.Type.KEY_UP) {

showPrevScreen();

}

}



[/java]

1 Like