Jump to content
  • Advertisement
Sign in to follow this  
EGD Eric

[java] how do you set the cursor position?

This topic is 4276 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'd like to be able to set the cursor position to be in the middle of the screen all the time, or maybe at 0, 0. Problem is, I can't find a function for setting the cursor position! (unlike SetCursorPos in Win32)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by capn_midnight
the AWT Robot is a good way to have fun on your friend's computers.

What do you mean by that?

Share this post


Link to post
Share on other sites
argh, its no good. robot.mouseMove actually generates a mouseMove event (go figure). I want my spaceship to turn with the mouse, but for the mouse's position to be reset to the center every time a mouseMove was detected. The very fact that mouseMove generates a mouseMove event means that all movement I try to do with the ship gets cancelled.

Share this post


Link to post
Share on other sites
Quote:
Original post by EGD Eric
argh, its no good. robot.mouseMove actually generates a mouseMove event (go figure). I want my spaceship to turn with the mouse, but for the mouse's position to be reset to the center every time a mouseMove was detected. The very fact that mouseMove generates a mouseMove event means that all movement I try to do with the ship gets cancelled.


Seems like you could programatically intercept that..


class MyMouseClass
{
int previousMouseX = 0;
int previousMouseY = 0;
int myMouseMovementX = 0;
int myMouseMovementY = 0;

void mouseMoved(MouseEvent e)
{
int dist_x = e.getX() - previousMouseX;
int dist_y = e.getY() - previousMouseY;
previousMouseX = e.getX();
previousMouseY = e.getY();

// check to intercept mouse movement that we caused
if (dist_x == myMouseMovementX && dist_y == myMouseMovementY)
{
myMouseMovementX = 0;
myMouseMovementY = 0;
return;
}

// go handle the mouse movement
doWhateverWithMouseMovement(dist_x, dist_y);

// reset the mouse location
int distToCenterX = centerX - e.getX();
int distToCenterY = centerY - e.getY();
myMouseMovementX = distToCenterX;
myMouseMovementY = distToCenterY;
Robot.mouseMove(distToCenterX, distToCenterY);
}
}

Share this post


Link to post
Share on other sites
programatically eh? I tried that, and it didn't work. Using the quick & dirty naive way that I was trying to do it. (with a boolean). your idea Pinacolada, works. That JInput thing looks interesting though.

Share this post


Link to post
Share on other sites
Could you not do something like.


class MyMouseClass
{
boolean isReseting;

void resetMouse()
{
isReseting = true;
Robot.mouseMove(0,0);
isReseting = false;
}

void mouseMoved(MouseEvent e)
{
if(isReseting)
return;

// TO DO
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!