我认为编写脚本很容易,只需单击鼠标,然后在每次3-6的时间内随机间隔地编写delay,但是当我运行代码时,似乎什么都没有发生?至少没有点击?有没有发现我可能用错了Robot?我读过JavaDoc。谢谢!
编辑1:我修正了最初的问题,并更新了我现在的工作代码。我唯一的另一个问题是,我如何减缓它的速度,!它的点击速度如此之快??
import java.awt.AWTException;
import java.awt.Robot;
import java.util.Random;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main
{
public static Robot robot = null;
public static void main(String[] args)
{
try {
robot = new Robot();
} catch (AWTException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
click(100000);
}
public static void click(int desiredAmount)
{
int counter = 0;
int low = 3;
int high = 6;
Random rand = new Random();
while (counter < desiredAmount)
{
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(rand.nextInt(high-low) + low);
++counter;
}
}
}发布于 2016-01-10 21:08:48
你的循环状况正确吗?应该是吧
while (counter < desiredAmount)https://stackoverflow.com/questions/34710700
复制相似问题