Last active
July 26, 2023 13:34
-
-
Save gaborbata/02db0cbbebbb16460b68065d260f7884 to your computer and use it in GitHub Desktop.
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.*; | |
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