Created
July 16, 2019 22:06
-
-
Save patakk/0193f32c6d1e6636fc5b0202866bb417 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.AWTException; | |
import java.awt.Robot; | |
import java.awt.*; | |
Robot robot; | |
void setup() { | |
size(600, 600); | |
try { | |
robot = new Robot(); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
void draw() { | |
background(255); | |
Point p = getScreenLocation(); | |
int px = (int)p.getX(); | |
int py = (int)p.getY(); | |
int mx = int(px + random(-20, 20)); | |
int my = int(py + random(-20, 20)); | |
robot.mouseMove(mx, my); | |
ellipse(mouseX, mouseY, 20, 20); | |
} | |
Point getScreenLocation() { | |
PointerInfo info = MouseInfo.getPointerInfo(); | |
Point p = info.getLocation(); | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment