Keylistener not triggered on down event

The left and right arrow are bound to a keylistener. But the onaction in the keylistener is only triggered when I release the key and then the boolean value is false. (there is no down event, only up event). Now the strange thing is, if a ui popup is showing, the left and right arrows do generate a down and up event (so the boolean gets a true and also a false value). Any idea why this is ?

@Ojtwist said: The left and right arrow are bound to a keylistener. But the onaction in the keylistener is only triggered when I release the key and then the boolean value is false. (there is no down event, only up event). Now the strange thing is, if a ui popup is showing, the left and right arrows do generate a down and up event (so the boolean gets a true and also a false value). Any idea why this is ?

Your mention of a “UI popup” makes me a little suspicious. Are you using nifty by any chance? It is likely that it is swallowing the events.

Make a simple test case without nifty and you will see that down and up events are delivered properly.

Yes I’m using nifty. How is it swallowing the events, when it is working when nifty a popup is present, but stops working when the popup is gone ?
Any idea what I have to look for to fix this?

I may have a possible idea, if you can show me:

*) the onAction line

*) the entire block of the boolean code for a single binding

*) and… whether the boolean starts off as true or false.

Just something I assume might work, no guarantees.

@cardboardman, sure.

[java] ActionListener keyListener = new ActionListener() {
public void onAction(String name, boolean KeyPressed, float tpf) {
if (Keys.containsKey(name)) {
int key = Keys.get(name);
tempkeystates.put(key, KeyPressed);
if (!previouskeystates.containsKey(key)) {
previouskeystates.put(key, false);
}
}
}
};[/java]

The boolean starts of with false (and only is triggered once as false). From what I’ve seen during debugging the normal behave is:

(key is down) TRUE …(key goes up) false.

Though I get.

(Key goes down) nothing happens at al … (key goes up) false.

@Ojtwist said: Yes I'm using nifty. How is it swallowing the events, when it is working when nifty a popup is present, but stops working when the popup is gone ? Any idea what I have to look for to fix this?

I have no idea what nifty is doing when, why, where, or how.

But if you made a simple test case without nifty then your buttons will work fine and then you could be sure it is nifty-related. If for some bizarre twist of the universe, you still don’t receive down events (while ever other JME user does) then you will have a simpler base to work from to solve the problem. (And if it doesn’t work then you could post that test case here.)

Nifty has been swallowing events since forever. Just saying.

This solution may be worth a shot, otherwise, do make a test case without nifty as suggested.

This has always worked for me as a hold down to run key, although I am not sure if it is compliant with your project:

[java]
if (Keys.containsKey(name)) {
if (!statename) {
statename = !statename;
//TRUE BLOCK
}
else {
statename = !statename;
//FALSE BLOCK
}
}
[/java]

The order is base on boolean starting off false. It wont hurt nothing if you flip the boolean to true and flip those blocks around.
If I ever needed a toggle instead of a hold with this, I just do:

if (Keys.containsKey(name) && KeyPressed) {stuff}