gpt4 book ai didi

java - Java Robot单击的速度为每秒70次单击,无法弄清楚数学/出了什么问题

转载 作者:行者123 更新时间:2023-12-03 13:09:18 25 4
gpt4 key购买 nike

 volatile private boolean mouseDown = false;

private int max = 0;
private int min = 0;
private Robot robot;

public MouseClickListener()
{
try
{
robot = new Robot();
} catch (AWTException e)
{
e.printStackTrace();
}
}

@Override
public void nativeMouseClicked(NativeMouseEvent nativeMouseEvent)
{

}

@Override
public void nativeMousePressed(NativeMouseEvent nativeMouseEvent)
{
if (nativeMouseEvent.getButton() == NativeMouseEvent.BUTTON1)
{
max = Native.get().getFrame().getCps().getValue() + Native.get().getFrame().getDev().getValue();
min = Native.get().getFrame().getCps().getValue() - Native.get().getFrame().getDev().getValue();
mouseDown = true;
initThread();
}
}

@Override
public void nativeMouseReleased(NativeMouseEvent nativeMouseEvent)
{
if (nativeMouseEvent.getButton() == NativeMouseEvent.BUTTON1)
{
mouseDown = false;
}
}

嗨,我基本上是在尝试制作一个自动点击器,该点击器单击JSlider的值(例如,介于9和13之间的随机值)。

因此,在单击鼠标时,将调用initThread方法,并计算出每秒的点击次数(介于JSlider值之间的随机数,该值是来自差异类),然后从中单击,然后将线程 hibernate 1/randomNum(以秒为单位),以便每秒单击多次。

由于某种原因,它的点击速度约为200cps,使我的计算机落后。有人看到我的代码有问题吗?

谢谢。

CLICKER的新代码;
    public class ClickMethod implements Runnable
{
@Override
public void run()
{
System.out.println("STARTED");
do
{
System.out.println("RUNNING");
Random r = new Random();
int random = r.nextInt((max - min) + 1) + min;
robot.mousePress(BUTTON1_MASK);
robot.mouseRelease(BUTTON1_MASK);
try
{
Thread.sleep(1000 / random);
} catch (InterruptedException e)
{
e.printStackTrace();
}
} while (mouseDown);
}
}

由于某种原因,此命令仅运行一次,然后在mouseDown变量更改时不会被调用。

最佳答案

如果希望您经常单击此按钮,那么它将创建许多线程,所有这些线程都可以单击

public void nativeMousePressed(NativeMouseEvent nativeMouseEvent)
{
if (nativeMouseEvent.getButton() == NativeMouseEvent.BUTTON1)
{
max = Native.get().getFrame().getCps().getValue() + Native.get().getFrame().getDev().getValue();
min = Native.get().getFrame().getCps().getValue() - Native.get().getFrame().getDev().getValue();
mouseDown = true;
initThread();
}
}

您需要从那里删除initThread()并在某个地方(例如在构造函数中)调用一次。

关于java - Java Robot单击的速度为每秒70次单击,无法弄清楚数学/出了什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41838790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com