+ Reply to Thread
Results 1 to 6 of 6

Thread: Detecting the speed of the mouse

  1. #1

    Default Detecting the speed of the mouse

    Does anyone know a way to detect the speed of the mouse? By that I mean: how quickly is the mouse being moved at a given moment in the X and Y directions.

    Of course it sounds simple... take the current position minus last position, take the elapsed time, divide the two and you're done. The problem with that is that the mouse will go out of the window eventually or hit the side of the screen and stop moving. So it seems that you need to keep re-centering it's position.

    I've tried setting the mouse position on every frame back to the screen center and seem to be getting random or inconsistent results. Sometimes, even though I'm moving the mouse left, I get an occasional glitch where it appears to have moved right. And vice versa. I think this may be because I'm setting the mouse position too often. Not sure.

    Is there an easy way to just get the speed of the mouse without having to make guesses and reset the position continuoulsy?

    Thanks

  2. #2
    Member
    Join Date
    Jul 2004
    Location
    Sweden
    Posts
    65

    Default

    Have you tried to read and reset only 5-10 times a second instead of every frame? If you read every frame you might be reading more often than the computer reads the input from the mouse.

    What about the mouse acceleration, does the different settings on that affect your speed-check?
    Mikael Linusson
    Nordic Software for Entertainment
    http://www.nordicsoftware.se

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Location
    Austria
    Posts
    968

    Default

    In directx you can read the relative mouse movement.
    Something like:

    Code:
    Mouse->GetDeviceState(sizeof(DIMOUSESTATE),&dims);  //read mouse
    mousex=mousex+dims.lX		// relative x movement
    mousey=mousey+dims.lY;		// relative y movement
    Karl Hofer
    Blueskied Games (main site), Gratis Spiele (german site)

  4. #4

    Default

    Quote Originally Posted by Linusson
    Have you tried to read and reset only 5-10 times a second instead of every frame? If you read every frame you might be reading more often than the computer reads the input from the mouse.

    What about the mouse acceleration, does the different settings on that affect your speed-check?
    I have something like that actually; it's not really every frame, but every 20 milliseconds (or more) that I read. I've tried different values for how often I read and found 20 to give slightly better results than say, 50. I've also tried averaging over 5 reads discarding what appears to be random noise. Results are better, but still seem to be inconsistent.

    Haven't tried it with accceleration on.

    - Alan

  5. #5

    Default

    Quote Originally Posted by Wayward
    The Mouselook thread in the GameDev Forum may answer your question, depending on what OS/API you're using.
    Thanks, I'll have a look at that.

    Edited to add:
    I did have a look at that and discovered something interesting...

    As usual, simply ignore the result from "GetTickCount" and assume a constant amount of time between calls. That, plus the averaging and discarding of noise, seems to smooth it out perfectly!

    - Alan
    Last edited by twilightsupport; 08-28-2004 at 05:48 PM.

  6. #6
    Senior Member
    Join Date
    Jul 2004
    Posts
    1,216

    Default

    The polling intervall differs.

    serial: 40hz
    usb: 125hz
    ps2: 60, 80, 100 or 200hz (these are the common rates)

    I just mention it because not knowing that could lead to a somewhat odd behaviour of your programm.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts