Skip to content

Instantly share code, notes, and snippets.

@patakk
Created July 16, 2019 22:06
Show Gist options
  • Save patakk/0193f32c6d1e6636fc5b0202866bb417 to your computer and use it in GitHub Desktop.
Save patakk/0193f32c6d1e6636fc5b0202866bb417 to your computer and use it in GitHub Desktop.
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