Created
May 17, 2023 21:50
-
-
Save salah3x/3ec6b0580b347ce1c5b7e90e753edd79 to your computer and use it in GitHub Desktop.
Prevent monitors from going to sleep by regularly moving the mouse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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