Home > other >  Java - robot. Mousepress "Auto Clicker" how to make it stop?
Java - robot. Mousepress "Auto Clicker" how to make it stop?

Time:05-23

I found a code to make automatically click for the entertainment.
I will use what code to click on the stop? I want to use A similar Key listeners to stop it. Like to press the space bar and enter to start and stop.
This is the code:

Import the Java. The awt. AWTException;
Import the Java. The awt. Robot;
Import the Java. The awt. Event. InputEvent;
Import the Java. IO. BufferedReader;
import java.io.IOException;
Import the Java. IO. InputStreamReader;


Public class AutoClicker {

Public static int rate=0;

Public static void main (String [] args) {

While (rate==0) {
Try {
System. The out. Println (" Speed of the auto - clicker (in miliseconds) : ");
BufferedReader in=new BufferedReader (new InputStreamReader (System. In));
Try {
Rate=Integer. The parseInt (in readLine ());
If (rate & lt; 500) {
Rate=0;
System. The out. Println (" Must be at further 500 miliseconds. ");
}
{} to catch (a NumberFormatException ex)
System. The out. Println (" Error - both please try again. ");
}
} the catch (IOException e) {}

}
Try {
Robot Robot=new Robot ();
While (true) {
Try {
Thread.sleep (rate);
Robot. MousePress (InputEvent. BUTTON1_MASK);
Robot. MouseRelease (InputEvent. BUTTON1_MASK);
{}} catch InterruptedException (ex)
}
} the catch (AWTException e) {}
}

}

CodePudding user response:

Replace

While (true)

Use the

While (//keyevent here//!=true)

Therefore, before the specified button, it will continue to cycle once keyevent is equal to the true, the flash will stop automatically.

CodePudding user response:

I wrote the if (KeyEvent!=true), the compile error
  • Related