Java机器人鼠标移动:设置速度?

发布于 2024-10-22 04:38:49 字数 190 浏览 2 评论 0原文

Java Robot 类允许人们移动鼠标,就像移动实际的物理鼠标一样。

然而,如何以人性化(而非即时)的方式将鼠标从 Point1 移动到 Point2?又名,如何设置移动速度?

如果Robot类不可能达到这样的速度,那么如果鼠标只能瞬时移动,那么应该使用什么样的“算法”来模仿人类的鼠标移动?是否应该以一定的递增速度逐像素移动鼠标?

The Java Robot class allows one to move the mouse as if the actual physical mouse was moved.

However, how does one move the mouse from Point1 to Point2 in a humane (and thus not instant) manner? Aka, how does one set the speed of movement?

If no such speed is possible with the Robot class, thus if the mouse can only be moved instantenously, what kind of "algorithm" should be used to mimic a human's mouse movement? Should it move the mouse pixel by pixel with a certain incrementing speed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小清晰的声音 2024-10-29 04:38:49

这里有一个非常好的方法:

考虑鼠标开始的 start_x 和您希望鼠标结束的 end_xy 也一样

for (int i=0; i<100; i++){  
    int mov_x = ((end_x * i)/100) + (start_x*(100-i)/100);
    int mov_y = ((end_y * i)/100) + (start_y*(100-i)/100);
    robot.mouseMove(mov_x,mov_y);
    robot.delay(10);
}

希望有帮助......

Here is a pretty good way here:

Consider start_x where your mouse starts and end_x where you are wanting it to end. Same for y

for (int i=0; i<100; i++){  
    int mov_x = ((end_x * i)/100) + (start_x*(100-i)/100);
    int mov_y = ((end_y * i)/100) + (start_y*(100-i)/100);
    robot.mouseMove(mov_x,mov_y);
    robot.delay(10);
}

Hope that helps...

奈何桥上唱咆哮 2024-10-29 04:38:49

Robot 类有一个delay(...) 方法,您可以使用它来控制从一个点到另一个点的移动。尝试几种不同的算法来确定您喜欢的算法。

The Robot class has a delay(...) method that you can use to control movement from point to point. Try a few different alogorithms to determine what you like.

梦途 2024-10-29 04:38:49

重写 Geoff 的答案以便于理解:

for (int i=0; i<=100; i++){
   int mov_x = start_x + (end_x - start_x) * i/100;
   int mov_y = start_y + (end_y - start_y) * i/100;
   robot.mouseMove(mov_x,mov_y);
   robot.delay(10);
}

Rewrite Geoff's answer for easier understanding:

for (int i=0; i<=100; i++){
   int mov_x = start_x + (end_x - start_x) * i/100;
   int mov_y = start_y + (end_y - start_y) * i/100;
   robot.mouseMove(mov_x,mov_y);
   robot.delay(10);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文