Don’t move the mouse if mouse has moved in last 60 seconds.
import java.awt.*;
import java.util.*;
public class KL {
private int x=0;
private int y=0;
public static void main(String[] args) throws Exception {
KL kl = new KL();
kl.setXY();
Robot hal = new Robot();
Random random = new Random();
while(true) {
int storedX = kl.getX();
int storedY = kl.getY();
hal.delay(1000*60);
kl.setXY();
if ( (storedX==kl.getX()) && (storedY==kl.getY()) ) {
int x = java.lang.Math.abs(random.nextInt() % 640);
int y = java.lang.Math.abs(random.nextInt() % 480);
System.out.println("(x,y) = " + x + " , " + y);
hal.mouseMove(x,y);
kl.setXY();
} else {
System.out.println("Mouse already moved, current position: (x,y) = " + kl.getX() + " , " + kl.getY());
}
}
}
public void setXY() {
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
setX(x);
setY(y);
}
public void setX(int xval) {
x = xval;
}
public void setY(int yval) {
y = yval;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}