Mouse Not Returning Proper X/Y changes?

I’ve been trying to translate the position of the Mouse to actual X/Y coordinates, using two integer variables mouseX and mouseY. When the program starts, I use java.awt.Robot to move the mouse to 300,300 and set the mouse position to that point. Then, every time I poll the mouse I add the value of its x component and its y component to the position variables, because what I understood as the mouse value was what its pixel change was. However, when I output the mouse values, they are completely wrong, changing much more over the same distance if I move the mouse slowly rather than quickly, sometimes eventually becoming entirely negative (which is obviously wrong).

Any ideas?

From the directx documentation

[quote]The data returned for the x-axis and y-axis of a mouse indicates the movement of the mouse itself, not the cursor. The units of measurement are based on the values returned by the mouse hardware and have nothing to do with pixels or any other form of screen measurement. Because Microsoft?DirectInput?communicates directly with the mouse driver, the values for mouse speed and acceleration set by the user in Control Panel do not affect this data.
[/quote]
So, erm, your screwed :(.

There are a number of things that might cause the negative data. The driver is one, the value from the mouse driver might be velocity, not distance moved, so you would need to factor time into figuring out the distance moved. You might also be filling the buffer when the mouse is moving quickly. In the old version of jinput it dumped a statement out when the buffer overflowed. I could do a magic build with it back in, just to see if this is your problem.

You might want to consider trying the raw plugin, but I suspect that again it talks to the mouse driver direct.

edit: The AWT plugin will give you the mouse movement in pixels.

Endolf

Okay, I’ll look into the AWT plugin. For now, I simply made a certain key combination plus the arrow keys would move your mouse around, thereby allowing absolute mouse position control. The only problem with this, of course, is that if someone wants to record the key presses and mouse movements at the same time – then the buttons used to move the mouse can’t be recorded.

I also thought of perhaps getting the mouse movement difference, then constraining it by moving it a set number of positive pixels with any sort of positive movement, and the same for negative movement. I didn’t use this because it had the potential to get frustrating, and the OS still had use of the mouse so quite often it was moving where it should, then hopping to where I wanted it to be pretty awkwardly.

In any case, I’ll check out the AWT plugin. Where exactly can I find it, by the way? And is it an AWT plugin for JInput, or for Java? I’m Googling it now, but the results so far aren’t so great.

It should be in the jinput jar already. specify the property jinput.plugins with the value net.java.games.input.AWTEnvironmentPlugin

HTH

Endolf

Excellent, I’ll take a look. Thanks. :slight_smile:

Okay, I’ve looked at it, and I don’t quite understand what you want me to do. I found the AWTEnvironmentPlugin and got the controller from that instead of a ControllerEnvironment, but that makes no difference to anything as far as I can tell. And there is a jinput.util.plugins folder with Plugin, PluginLoader, and Plugins classes, but I am unsure what you want me to do with them.

Thanks.

java -cp <your jar here>;jinput.jar -Djava.library.path=<path you dll's> -Djinput.plugins=net.java.games.input.AWTEnvironmentPlugin <your main class here>

Then just get the controllers from the

ControllerEnvironment.getDefaultEnvironment().getControllers()

as before. You should find some new controllers in there. One of which would be a mouse.

HTH

Endolf