Simulate input?

Hi, I currently try to find this in the Inputmanager, but fail to find it.
Is there any way to simulate keyevents in jme?

Baiscally I have two uses for this;

  1. automated testing, by building a player bot that does some procedures like build a complete spaceship and check the results if I introduced errors. (And yes I know i could do this via robot, but it makes it way more instable that way, as the jme window position suddenly is important, the resolution ect. When in just need to do like press a,w,d,d,l,n

  2. JME-JFX consumes events it thinks that are for JFX, however occasinally it consumes events it should not consume.
    Eg it has focus , and thus consumes a key press, however it is found out it has no handler instead the key was meant for jme itself. (Like pressing W to walk forward while jfx has focue) I now want to unfocus jfx 8the easier part) and then redirect the event again to jme, so that it behaves as expected. Since jfx runs in a different thread, there is no easy way to detect such cases before the event is transfered to jfx in the first place.

From my seeing I could use onKeyEvent to push my events into JME, however I would need to do so in the ventsPermitted phase, any ideas how to archive this?

My currently hacky idea would be to use a RawInputListener, add a queue to it, and on beginInput inject my own events, however this feels pretty dirty.

Do I miss something, or is there simply no way to simulate Events currently?

2 Likes

There is no way to do this. For automation, you could try using the Java robot stuff: http://docs.oracle.com/javase/6/docs/api/java/awt/Robot.html

(2) is a trickier issue to handle properly… and JME provides no mechanism. It’s odd that you are forced to consume the event in JFX.

When I looked at this before, there was no good place to inject these sorts of events without causing issues.

1 Like

Event handling happens at the beginning of the frame and it is allowed to propagate only if the RawInputListener doesn’t specify that it handled the event.
Is there a way you can determine whether JFX handled the key event or not when forwarding it? Or does that happen asynchronously?

JFX runs in its own thread, similar to jme.
I can only enqueue it, and one pulse (aka jme frame in jfx) later i know if I need to not consume it.

Since any and every element in JFX could recieve key events i never know if the focused ones are actually consuming it before.