Skip to content

Instantly share code, notes, and snippets.

@gaborbata
Last active July 26, 2023 13:34
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 gaborbata/02db0cbbebbb16460b68065d260f7884 to your computer and use it in GitHub Desktop.
Save gaborbata/02db0cbbebbb16460b68065d260f7884 to your computer and use it in GitHub Desktop.
import java.awt.*;
import java.awt.event.*;
public class Caffeine {
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
while (true) {
try {
int xMove = Math.random() < 0.5 ? 1 : -1;
int yMove = Math.random() < 0.5 ? 1 : -1;
Point loc = MouseInfo.getPointerInfo().getLocation();
robot.mouseMove((int) loc.getX() + xMove, (int) loc.getY() + yMove);
//System.out.println(String.format("event triggered at %s", loc));
} catch (Exception e) {
//System.out.println(String.format("could not trigger event: [%s], falling back to keypress", e.getMessage()));
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
Thread.sleep(30000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment