Skip to content

Instantly share code, notes, and snippets.

@leraux
Last active July 3, 2021 07:31
Show Gist options
  • Save leraux/583276f61a9a594d0643418de98c5035 to your computer and use it in GitHub Desktop.
Save leraux/583276f61a9a594d0643418de98c5035 to your computer and use it in GitHub Desktop.
Mouse Click operation on every 3 second for infinite time
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.awt.event.InputEvent;
public class MouseClick {
public static void main(String[] args) {
while (true) {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point point = pointerInfo.getLocation();
int x = (int) point.getX();
int y = (int) point.getY();
try {
Robot robot = new Robot();
robot.mouseMove(700, 300);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseMove(x, y);
Thread.sleep(3 * 1000);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment