I am writing code to click different colored pixels on my screen, and I need a way to stop it. I have tried the noLoop() function in multiple places, but that did not work. Does anyone have any idea of how to reliably stop it when exported to an executable program? I am open to optimizations as well.
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
Robot colourSearcher;
boolean isRunning;
boolean hasClicked;
int dist;
void setup()
{
size(10, 10);
try
{
colourSearcher= new Robot();
}
catch(AWTException e)
{
System.out.println("Your robot could not be created!");
}
isRunning= false;
}
void draw()
{
BufferedImage screenShot= colourSearcher.createScreenCapture(new Rectangle(0, 0, displayWidth, displayHeight));
for (int x= 1; x<screenShot.getWidth(); x++)
{
for (int y= 0; y<screenShot.getHeight(); y++)
{
int pixelValue= screenShot.getRGB(x, y);
if (pixelValue!=screenShot.getRGB(x-1, y))
{
colourSearcher.mouseMove(x, y);
colourSearcher.keyPress(InputEvent.BUTTON1_MASK);
colourSearcher.keyRelease(InputEvent.BUTTON1_MASK);
hasClicked= true;
if (hasClicked) break;
}
if (hasClicked) break;
}
}
}
Im assuming noLoop has an issue with one of the imports, for me, your example code makes my mouse go crazy moving on its own lol, not sure how to fix the issue for you but maybe put the draw loop in an if statement controlled by a boolean