• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get x,y coords outside of windows/screen using mouselook technique

 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you move your mouse all the way to the left - it hits the left edge of the screen and stops - even if the user keeps moving his mouse to the left.

In Java, there doesn't appear to be any way to detect that the user keeps moving his mouse "left".

Basically, if the current mouse coords are 50,100 and I move my mouse 10 feet to the left on my desk Java will still only report the position as 0,100.

My problem is, not only do I have to detect that the user moved the mouse to location -32535235,100 I also have to detect that position accurately.

In order to accomplish this, I'm doing the following:

1) Use robot class to forcefully move the cursor to the center of the screen.
2) Detect relative mouse movements and some Point which keeps track of the total movement
3) Repeat - go back to step 1

The code I'm using is basically straight out of a Java game development book "Developing Games in Java". This technique appears to work well for reporting simple changes in the relative x,y movement. It does not appear to be accurate in reporting actual x,y coordinates.

So my test case is this:

1) Start the application.
2) Move the mouse 1 foot to the left (left side of desk) - record the X location
3) Move the mouse 2 feet to the right (right side of desk)- record the X location.
4) Finally, move the mouse back to the left side of the desk and ensure it is the same (or very close) to the location recorded in step 2.

Currently when I do this, it's way off by hundreds of pixels.

Is there a simple error in the code that I'm missing? Any ideas on how I can accomplish this?

Here's the code:

[ August 14, 2007: Message edited by: Jonathan Janisch ]
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The recentering seems to work fine, and your "location" print out seems to move around fine.

EDIT - Nvmd, I see a bias towards the negative X.

EDIT 2 - I think your code works fine, because of the differences in mouse acceleration. You typically cannot expect 1 foot on your table top = x number of pixels.

If I move the mouse back and forth multiple times, it seems to hover around the same point.
[ August 20, 2007: Message edited by: Chu Tan ]
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Craig, I appreciate the time you put into your response. It's not really what I was attempting to accomplish though

Chu, thanks. This isn't really important - it's really just an experiment for fun. I wanted to make a cheap digital whiteboard using only a small mouse and a projector.

In order to do that I needed to be able to map positions on the whiteboard to screen coordinates. I attempted to solve that by first entering a configuration mode where the user clicks the top left, bottom left, and bottom right of the whiteboard - but I'm having issues getting those coordinates reliably.
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jonathan Janisch:
So my test case is this:

1) Start the application.
2) Move the mouse 1 foot to the left (left side of desk) - record the X location
3) Move the mouse 2 feet to the right (right side of desk)- record the X location.
4) Finally, move the mouse back to the left side of the desk and ensure it is the same (or very close) to the location recorded in step 2.

Currently when I do this, it's way off by hundreds of pixels.

Is there a simple error in the code that I'm missing?


You seem to be presuming that screen-pixels-per-mouse-inch is constant, but that's not the case. Modern UI standards typically call for a fast mouse-inch to move the cursor more pixels than a slow mouse-inch.

You can try this yourself. Place your mouse against the right side of your keyboard (or laptop), move the mouse quickly rightward, now slowly move the mouse leftward until it abuts the keyboard again. The mouse is back where it started, but the screen cursor will not be.

You might be able to find an OS (or perhaps just a mouse driver) that lets you set custom mouse acceleration curves. In that case you could set a flat curve and it might work the way you want it to. (Or try disable mouse acceleration on google.)
 
Jonathan Janisch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Brian, I did not know that!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic