我想使用Robot类为在线游戏编写一个机器人。我现在的问题是,Thread.sleep()或robot.delay()方法太不准确了。在游戏之外,它们工作得非常好,偏差大约只有2-3毫秒。但当游戏处于焦点位置时,这些方法的偏差为+5 - +20毫秒甚至更多。令人遗憾的是,这足以让我的机器人无法使用。有没有办法让这些方法更准确呢?或者,有没有其他方法来解决这个问题?
发布于 2020-08-30 00:03:14
没有区别
如果对JDK执行browse the source,Robot.delay()最终会调用Thread.sleep()。
public void delay(int ms) {
checkDelayArgument(ms);
Thread thread = Thread.currentThread();
if (!thread.isInterrupted()) {
try {
Thread.sleep(ms);
} catch (final InterruptedException ignored) {
thread.interrupt(); // Preserve interrupt status
}
}
}你也许可以给Java进程一个比游戏更高的优先级,任务在交给调度器之后可能会执行得更快。
https://stackoverflow.com/questions/63648846
复制相似问题