[java] how do you set the cursor position?
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)
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?
Easy to figure.. you can do a lot of stuff with the mouse - even remotely, or coding a trojan :D
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.
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); } }
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.
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 } }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement