I’m trying to use the arrow keys for movement in the game but nifty is consuming those events. So I’m wondering how to change the inputmappings. I tried the following:
boolean keyEvent(NiftyInputEvent inputEvent)
handle a key event.
Parameters:
inputEvent - key event to handle
Returns:
true when the event has been consumend and false if not
Same issue, but I was hoping to take it a step farther.
While this solution prevented nifty from consuming the input, it does not prevent nifty from making use of the input event. Is there a way to prevent this?
That is to say, while pressing the up key a character on the screen will move forward but nifty will also be switching focus on any buttons. And if the enter key is bound to an action it will also trigger whatever nifty button happens to have focus.
if you don’t want nifty to execute any code don’t bind any key or implement an KeyInputHandler with no behaviour.
[java]
public class EmptyNiftyKeyInputHandler implements KeyInputHandler{
public boolean keyEvent(NiftyInputEvent inputEvent) {
return false;
}
}
[/java]
If you want instead that both get the event, do what you need in keyEvent() and still return false.
With your code, both my input manager & nifty are receiving the key event.
Without your code, only nifty receives the key event
Nifty binds the following keys automatically:
The arrow keys & tab key will cycle focus on nifty controls
And the enter/return key will execute a nifty control, such as a button, if it has focus.
I was looking for a way to disable this behavior.
I may have found a solution,
which was to remove the “focusable” flag in the .xml for all nifty controls on my screen. I’m not sure if nifty is making use of any other keys that I don’t know about, but for the moment this seems to be a good workaround.