Java Robot类模拟人类鼠标移动 [英] Java Robot class simulating human mouse movement

查看:2740
本文介绍了Java Robot类模拟人类鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个关于远程控制的项目,从客户端向服务器发送conrdinate x和y游标。

I am working on a project about remote control, send conrdinate x and y of cursor from client to server.

但是

robot.mouseMove(x,y);

只会将光标移动到特定点,而不会将光标从原点移动

will only move the cursor to the particular point without moving the cursor form origional point

我发现这个简单的algorthim来模拟鼠标的持续移动

I have find this simple algorthim to simulate the continuing movement of mouse

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

但是这个algorthim仍然太简单了,它只是从一个点移动到另一个点慢慢地,这仍然不像人类的行为。

But this algorthim still too simple, it just move from one point to other point slowly, which still unlike human behave.

我从网上读过一些关于远程控制的开放式驱动代码,我发现这个项目
http://code.google.com/p/java-remote-control/
正在使用该方法从MouseListener类调用MosueMovement,用于执行拖动。

I have read some open soruce code about remote control from web, and I find this project http://code.google.com/p/java-remote-control/ is using the method call MosueMovement from MouseListener class, which they use to perform the "dragging".

我想知道有没有人知道更好的方法呢?

I like to know is any one know the better way of doing this?

推荐答案

如果你想让人工运动变得自然,有几点需要考虑:我想:

There are a few things to consider if you want to make the artificial movement natural, I think:


  1. 由于鼠标指针绕手腕转动,因此人体鼠标移动通常呈轻微弧度。另外,水平移动的弧度比垂直移动更明显。

  2. 人类倾向于向大方向移动,经常超过目标,然后回到实际目标。

  3. 朝向目标的初始速度非常快(因此上述过冲),然后对于精确定位而言稍微慢一些。但是,如果光标最初接近目标,则不会发生快速移动(也不会发生过冲)。

但是,在算法中制定这一点有点复杂。

This is a bit complex to formulate in algorithms, though.

这篇关于Java Robot类模拟人类鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆