我已经找到代码来制作一个娱乐用途的自动点击程序。
我将使用什么代码来停止点击器?我希望能用关键侦听器之类的东西让它停下来。例如,通过按空格键和enter键来启动和停止。
代码如下:
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AutoClicker {
public static int rate = 0;
public static void main (String[] args) {
while (rate == 0){
try{
System.out.println("Speed of the auto-clicker (in miliseconds):");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
rate = Integer.parseInt(in.readLine());
if (rate < 500) {
rate = 0;
System.out.println("Must be at least 500 miliseconds.");
}
} catch (NumberFormatException ex) {
System.out.println("Error - please try again.");
}
} 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) {}
}
}catch (AWTException e) {}
}
}发布于 2013-12-17 00:20:58
而不是
While(true)使用
While(//keyevent here// != true)所以,在你按下你指定的按钮之前,它会继续循环,一旦keyevent等于true,自动点击就会停止。
https://stackoverflow.com/questions/20615451
复制相似问题