Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created July 17, 2011 05:54
Show Gist options
  • Save brand-it/1087252 to your computer and use it in GitHub Desktop.
Save brand-it/1087252 to your computer and use it in GitHub Desktop.
I cool mouse robot system that works great. May work for you as well.
public class MouseRobot {
private void mouseRebotReplace(MouseEvent e) {
int x = e.getX() - pCenterX;
int y = e.getY() - pCenterY;
if (!isPaused) {
if (mouseX < 0) {
mouseX = 0;
} else if (mouseX > pWidth) {
mouseX = pWidth;
} else if (mouseY < 0) {
mouseY = 0;
} else if (mouseY > pHeight) {
mouseY = pHeight;
} else {
mouseX += x;
mouseY += y;
}
try {
robot = new Robot();
robot.mouseMove(mouseCenterX, mouseCenterY);
} catch (AWTException e1) {
e1.printStackTrace();
}
}
}
private void mouseRebotReplace(MouseEvent e) {
int x = e.getX() - pCenterX;
int y = e.getY() - pCenterY;
if (!isPaused) {
if (mouseX < 0) {
mouseX = 0;
} else if (mouseX > pWidth) {
mouseX = pWidth;
} else if (mouseY < 0) {
mouseY = 0;
} else if (mouseY > pHeight) {
mouseY = pHeight;
} else {
mouseX += x;
mouseY += y;
}
try {
robot = new Robot();
robot.mouseMove(mouseCenterX, mouseCenterY);
} catch (AWTException e1) {
e1.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment