Mouse tracking outside of the screen using Processing
This code borrows MouseInfo from JAVA to get coordinates outside of Processing’s display window. It also includes the ability to compile a PDF when you’re done by pressing the UP key in the sketch. Enjoy.
// trackScreen by Colin Owens
// Using JAVA mouseInfo for a bit of hackiness
// Use to your heart's content with attribution
// 2010
import processing.pdf.*;
Point mouse;
float weight = .05;
int lastX, lastY;
int aa = 0;
void setup() {
background(255);
size(screen.width,screen.height);
mouse = MouseInfo.getPointerInfo().getLocation();
lastX = mouse.x;
lastY = mouse.y;
smooth();
beginRecord(PDF, "filename.pdf");
println("I'm running");
}
void draw(){
mouse = MouseInfo.getPointerInfo().getLocation();
noStroke();
fill(0,10);
if(lastX == mouse.x && lastY == mouse.y) {
noFill();
stroke(aa,10);
strokeWeight(1);
ellipse(mouse.x,mouse.y, 20+weight,20+weight);
noStroke();
fill(255,03);
ellipse(mouse.x,mouse.y, 10+weight,10+weight);
weight = weight+.05;
}
else {
stroke(aa);
strokeWeight(.5);
line(lastX, lastY,mouse.x,mouse.y);
weight = .05;
}
lastX = mouse.x;
lastY = mouse.y;
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
endRecord();
exit();
}
}
}

