Skip to content

Instantly share code, notes, and snippets.

@bond-
Last active January 6, 2023 21:27
Show Gist options
  • Save bond-/65f1651dd0c4e12e31cbcbdfa4ac1615 to your computer and use it in GitHub Desktop.
Save bond-/65f1651dd0c4e12e31cbcbdfa4ac1615 to your computer and use it in GitHub Desktop.
Mouse Mover to avoid screen going to autosleep
import java.awt.*;
import java.util.Random;
// For Mac devices accessibility needs to be turned on (in System Preferences) for the parent process that runs this program.
public class Main {
public static void main(String[] args) throws AWTException {
int min = 0;
GraphicsDevice defaultScreenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int maxX = defaultScreenDevice.getDisplayMode().getWidth();
int maxY = defaultScreenDevice.getDisplayMode().getHeight();
int xCoord = 0;
int yCoord = 0;
Random random = new Random();
Robot robot = new Robot();
// Move mouse with a delay of 60secs between each move
robot.setAutoDelay(60000);
// Move for 480 mins or 8 hours
for (int i = 0; i < 480; i++) {
robot.mouseMove(xCoord, yCoord);
xCoord = random.nextInt(maxX - min + 1) + min;
yCoord = random.nextInt(maxY - min + 1) + min;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment