Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Multiple Mouse Events? >< ?  (Read 3543 times)
0 Members and 1 Guest are viewing this topic.
Offline Brick

Junior Newbie





« Posted 2008-04-17 19:04:03 »

I'm polling the mouse events and iterating through them using the following code ...

1  
2  
3  
4  
5  
6  
7  
8  
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!

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #1 - Posted 2008-04-17 19:16:44 »

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

Offline Brick

Junior Newbie





« Reply #2 - Posted 2008-04-17 19:45:24 »

Thanks for the quick reply I have 1 other that will take a bit to set up.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline brick2

Junior Newbie





« Reply #3 - Posted 2008-04-17 21:14:37 »

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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
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.
Offline DzzD
« Reply #4 - Posted 2008-04-17 22:00:15 »

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

Offline brick2

Junior Newbie





« Reply #5 - Posted 2008-04-17 22:07:17 »

no option to consume the net.java.games.input.Event. Sad

Decided to try and same thing it would report it multiple times(1-7) per mouse move.
1  
System.out.println( mouse.getX().getPollData() + ", " + mouse.getY().getPollData()); 
Offline DzzD
« Reply #6 - Posted 2008-04-17 22:15:28 »

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

Offline brick2

Junior Newbie





« Reply #7 - Posted 2008-04-17 22:27:04 »

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

Junior Newbie





« Reply #8 - Posted 2008-04-17 22:40:36 »

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
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #9 - Posted 2008-04-17 23:44:32 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline brick2

Junior Newbie





« Reply #10 - Posted 2008-04-17 23:46:45 »

thanks ill give it try keep me posted.
Offline brick2

Junior Newbie





« Reply #11 - Posted 2008-04-18 03:12:29 »

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)) >< ><
Offline Blackravenxt

Junior Newbie





« Reply #12 - Posted 2008-06-22 08:04:39 »

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 Smiley Smiley Smiley.  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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!