Multiple Mouse Events? >< ?

I’m polling the mouse events and iterating through them using the following code …


mouse.poll();
            EventQueue queue = mouse.getEventQueue();
            Event event = new Event();
            while(queue.getNextEvent(event)){
                  //Removed code using println() for testing purposes only.
                System.out.println(event.getComponent().getIdentifier() + ", " + event.getComponent().getPollData());
                  //More removed code.
            }

I’m getting the following results:
x, -43.0
x, -43.0
x, 42.0
x, 42.0
x, 42.0
…etc etc.
where in reality the mouse only moved -43 units one time and then +42 units one more time. Anyone know a workaround or if there is a better method for using JInput to track relative mouse location. ( Would prefer to use the events instead of mouse.getX().getPollData(); )

Thanks!

You appear to be doing everything right, I’ve not seen this and can’t explain it. Do you have any other mice or systems you can try your application with?

Endolf

Thanks for the quick reply I have 1 other that will take a bit to set up.

Other system is a no go wife took the laptop with her. I’ve double check there are no stray copies of the jar/dlls in jdk/jre/lib/ext and jre/lib/ext. I re-wrote a smaller extremely basic program just to make sure there we’re no threading issues or overlap…anywhere …i.e.



package test;

import javax.swing.JFrame;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Event;
import net.java.games.input.EventQueue;
import net.java.games.input.Mouse;

public class Main {

    private Mouse mouse;
    
    public Main(){
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
        Controller[] controllers = ce.getControllers();
        for(int i = 0; i < controllers.length; i++){
            if(controllers[i].getType() == Controller.Type.MOUSE)
                mouse = (Mouse)controllers[i];
        }
        while(true){
            if(mouse != null){
                mouse.poll();
                EventQueue queue = mouse.getEventQueue();
                Event event = new Event();
                while(queue.getNextEvent(event)){
                    System.out.println(event.getComponent().getIdentifier() + ", " + event.getComponent().getPollData());
                }
            }
        }
    }
    
    public static void main(String[] args) {
        new Main();
    }

}

and the results stay the same i actually get more events since the program runs quicker …i have 1 keyboard (logitech g15) and a 1 mouse (logitech g5) on windows xp. Any ideas ><? I also coded it in netbeans trying it with and without librarys/netbeans path.

have you tried to consume the event ?
event.consume()

no option to consume the net.java.games.input.Event. :frowning:

Decided to try and same thing it would report it multiple times(1-7) per mouse move.

System.out.println( mouse.getX().getPollData() + ", " + mouse.getY().getPollData()); 

ok I was thinking of AWTEvent, may be you can do some kind of distinct select… but that’s not the best way…

something like if last event time==current event time and last event value=event value and etc… then discard this event

something like that
if(lastevent.equals(newevent))
discard this event

Just tried that no solution. I’m looking at a log of the timestamps atm…I’m considering trying to update directx drivers.

I just made the system reporting a little more verbose…take a look…im about out of ideas.

This is from moving the mouse STRAIGHT left quickly and stopping.

Logitech HID-compliant G5 Laser Mouse component:x time:19491750000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491750000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491750000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491750000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491765000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491765000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491765000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491765000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491781000000 value:-1.0 poll data:-16.0
Logitech HID-compliant G5 Laser Mouse component:x time:19491781000000 value:-1.0 poll data:-16.0

I’m guessing that the duplicates are from the event queue being read multiple times. One work around might be at the end of your loop, save the timestamp of the last read event, and on the next cycle, only read events with a newer timestamp. This should do as a workaround. I think that a poll should probably clear the queue first. I’ll look in to it. I also note you are polling as fast as that tight loop will go. Maybe try a sleep in there so it only polls at 50hz or something. I normally have my main game loop call to the input component in it’s main loop, but the input layer only does a poll and update at about 50hz.

HTH

Endolf

thanks ill give it try keep me posted.

Tried storing the last events timestamp and only using events past that …that cut a few out but problems not solved. I also threw in a sleep thread ranging from 0-500ms which did nothing. : \ all my events work with key downs…mouse clicks just fine…its just the mouse movments x and y (not sure about z (mousewheel)) >< ><

Can’t remember my pw for “Brick” lol so… It’s 2:00 am and im working on another project… long given up on using JInput because of the previous errors. However I built a new comp since then quad core 2.5ghz 8gb ram 9800 gtx etc etc :slight_smile: :slight_smile: :). All of the sudden as like 8 alliance bum rushed blacksmith :wink: I realized my old computer had a program called “SetPoint” from Logitech that supported changing mouse speeds and accelerations. I could be wrong here but it seems like a pretty good stab in the dark for these errors.

Any have a comp with “SetPoint” for G5 and G9 gaming mice have any issues with JInput.