Skip to content

Instantly share code, notes, and snippets.

@salah3x
Created May 17, 2023 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salah3x/3ec6b0580b347ce1c5b7e90e753edd79 to your computer and use it in GitHub Desktop.
Save salah3x/3ec6b0580b347ce1c5b7e90e753edd79 to your computer and use it in GitHub Desktop.
Prevent monitors from going to sleep by regularly moving the mouse
import java.awt.*;
import java.awt.event.InputEvent;
public class NoSleep {
public static void main(String[] arg) throws Exception {
Robot robot = new Robot();
while (true) {
Point point = MouseInfo.getPointerInfo().getLocation();
robot.mouseMove((int) point.getX() + 200, (int) point.getY());
Thread.sleep(2_000);
point = MouseInfo.getPointerInfo().getLocation();
robot.mouseMove((int) point.getX(), (int) point.getY() + 200);
Thread.sleep(2_000);
point = MouseInfo.getPointerInfo().getLocation();
robot.mouseMove((int) point.getX() - 200, (int) point.getY());
Thread.sleep(2_000);
point = MouseInfo.getPointerInfo().getLocation();
robot.mouseMove((int) point.getX(), (int) point.getY() - 200);
Thread.sleep(2_000);
// robot.mousePress(InputEvent.getMaskForButton(1));
// robot.mouseRelease(InputEvent.getMaskForButton(1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment