This adapted code will:
- screen capture a small area at the center of your display monitor
- display the image at the center of the sketch window
- check for color(0xFF, 0xFF, 0xFF) (white) at the center of the sketch window
- I used white so I can move a window in and out of capture area
- it will display "“kaart gevonden” if white is at center
// Screen Scanner
// GLV 2021-06-07
// Adapted from:
color pas = color(0xFF, 0xFF, 0xFF);
robot = new Robot();
catch (Exception e)
Rectangle r = new Rectangle(displayWidth/2-100, displayHeight/2-100, 300, 400);
BufferedImage img1 = robot.createScreenCapture(r);
PImage img2 = new PImage(img1);
image(img2, width/2, height/2);
//get(x,y); // Not used in this code!
color colorFromGet = get(width/2, height/2); //Gets color from center of sketch window
// Examples of what you can do here:
//color colorFromGet = get(x, y);
//color colorFromGet = get(mouseX, mouseY);
if(colorFromGet == pas)
fill(0, 255, 0);
text("kaart gevonden", width/2, height/2);
println(hex(get(mouseX, mouseY))); //Gets color from mosue location and displays as hex
I just did a quick exploration of this; there are certainly other ways to do this.
You will have to go through code line by line and understand it.
Modify it as you wish.
There are resources (tutorials, references, examples, etc.) here:
Center of screen:
Center of screen with a window (this could be your app) moved into focus: