[SOLVED] Infrequent Mouse Movement Updates

Hello,

I want to use mouse motion as a trigger for actions. My code looks like this (small running example):

import com.jme3.app.SimpleApplication;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseAxisTrigger;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        flyCam.setDragToRotate(true);
    
        inputManager.addMapping("MouseMovement", 
                new MouseAxisTrigger(MouseInput.AXIS_X, false),
                new MouseAxisTrigger(MouseInput.AXIS_X, true),
                new MouseAxisTrigger(MouseInput.AXIS_Y, false),
                new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                System.out.println(name);
            }
        }, "MouseMovement");
    }
}

Unfortuanetly, this yields “MouseMovement” very infrequently. Sometimes I can move my mouse for seconds and no event seems to be emitted. I have also tried this setup in a project where there is more work than just printing a line so I am pretty sure this is no buffering issue. Framerate is constant around 75 (sorry, just intel graphics xD).
Do I use the MouseAxisTrigger in a wrong fashion or is there something else that might do the trick?
I’m running on Linux, JME 3.2.2.

Regards
theTiger

Try registering 1 listener for the x axis and 1 for the y

No difference, event with an individual listener for each positive and negative movement. Output does not difer at all if I use a single listener and add all events (XFalse, XTrue, YFalse, YTrue) to the listener.

import com.jme3.app.SimpleApplication;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseAxisTrigger;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        flyCam.setDragToRotate(true);
        
        inputManager.addMapping("XFalse", new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping("XTrue", new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping("YFalse", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping("YTrue", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        
        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                System.out.println(name);
            }
        }, "XFalse");
        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                System.out.println(name);
            }
        }, "XTrue");
        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                System.out.println(name);
            }
        }, "YFalse");
        inputManager.addListener(new ActionListener() {
            @Override
            public void onAction(String name, boolean isPressed, float tpf) {
                System.out.println(name);
            }
        }, "YTrue");
    }
}

The Events printed out are not wrong, but axis movement seems only be recognized with large and fast movements.

For reference: I expect the events happening like here: How to Write a Mouse-Motion Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

I don’t know why you’re seeing what you’re seeing, but FlyByCamera also adds those same mappings under different names. If you call this to clear all those mappings (before you add your own), I wonder if that changes the behavior?

inputManager.clearMappings();

Unfortunately no difference :frowning:
Can you reproduce the issue?

Oh, you have an ActionListener. Try AnalogListener.


    @Override
    public void simpleInitApp() {
        flyCam.setDragToRotate(true);

        inputManager.addMapping("MouseMovement",
                new MouseAxisTrigger(MouseInput.AXIS_X, false),
                new MouseAxisTrigger(MouseInput.AXIS_X, true),
                new MouseAxisTrigger(MouseInput.AXIS_Y, false),
                new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addListener(new AnalogListener() {
            @Override
            public void onAnalog(String name, float value, float tpf) {
                System.out.println(name + " " + tpf);
            }
        }, "MouseMovement");
    }

That’s it!! Thanks
I have read the javadoc of MouseAxisTrigger and there was no listener mentioned. Now after you write this I see it was also in the beginner series, but I think it would not hurt to mention this in the javadoc…

2 Likes