Archived

This topic is now archived and is closed to further replies.

[java] set the cursor position

This topic is 5148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing an opengl app is java and am currently working on the camera / movement system. The problem I am having is that I cannot find any way to keep the mouse cursor in the middle of the screen (windowed). I looked high and low through the java API but could not find anything to control the position of the mouse cursor. Could someone please help me figure this out? I am using AWT for my GUI, btw. Thanks.

Share this post


Link to post
Share on other sites
Ummm.... what if you read the relative movements of the mouse and rotate your scene accordingly, then draw your cursor in the middle of the screen and suppress the default one? So the cursor never really moves anywhere, just the scene itself. I think that should be enough to solve your problem. The Java API''s MouseListener interface can be used to react to relative mouse movements, I think.

Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett

Share this post


Link to post
Share on other sites
Yes, that is exactly what I want and was trying to do, I just need some help doing that.
quote:
The Java API''s MouseListener interface can be used to react to relative mouse movements, I think.
Ive looked and dont see anyway to do this. The fact is, once the cursor leaves the bounds of the awt frame, no events are triggered. Even if I were to supress the default cursor, and draw my own, the position of the mouse would still leave the bounds of my window. The problem is I have no hardware control of the mouse and its position so I cant stop the mouse from exiting my frame.

Example, this is a snippet of code I use in c++
GetCursorPos(&mousePos);	// Get the 2D mouse cursor (x,y) position					
SetCursorPos(mid_x, mid_y); // Set the mouse cursor in the middle of the window
// Get the movement deltas
delta_x = mid_x - mousePos.x;
delta_y = mid_y - mousePos.y;


I need to find the Java equivelent to SetCursorPos(int x, int y);
Anyone know?

Share this post


Link to post
Share on other sites