更顺畅地移动光标(远程应用程序)
我正在编写 Android 远程应用程序。当我触摸并移动 Android 应用程序时,服务器计算机上的光标也会移动,但会延迟大约一秒钟。
我的应用程序只是两个线程:客户端发送坐标,服务器接收坐标,仅此而已。 我的解决方案只是通过ObjectInputStream传递dx,dy并使用Robot::mouseMove来移动光标。
你能给我一些建议来防止光标延迟吗?(就像RemoteDroid一样流畅) ^^)
我的服务器:
public void run() {
..........
while(true) {
// get dx, dy from ObjectInputStream
........
moveMouseByDelta(dx, dy);
}
...........
}
private void moveMouseByDelta(int dx, int dy)
{
try {
Point p = MouseInfo.getPointerInfo().getLocation();
int currentX = p.x;
int currentY = p.y;
Robot robot = new Robot();
robot.mouseMove(currentX + dx, currentY + dy);
} catch (AWTException e) {
e.printStackTrace();
}
}
我的客户端(Android 远程应用程序):(
private void touchTouchPad(MotionEvent event)
{
int x = (int)event.getX();
int y = (int)event.getY();
switch(event.getAction()) {
............
case MotionEvent.ACTION_MOVE:
if(leftMouseHold) {
if(clientThread != null) {
int dx = x - xMouse;
int dy = y - yMouse;
xMouse += dx;
yMouse += dy;
clientThread.sendDelta(dx, dy);
}
}
break;
..............
}
}
这不是我的作业,这是我的学习)
编辑:添加更多信息
I am writing Android remote app. When I touch and move on Android app, the cursor on server machine moves too but it delays for about a second.
My app simply are two threads: client sends coordinates, server receives them and that's all.
My solution is just to pass dx, dy through ObjectInputStream and use Robot::mouseMove to move the cursor.
Can you give me some advices to prevent the cursor from delaying? (smoothly like RemoteDroid ^^)
My Sever:
public void run() {
..........
while(true) {
// get dx, dy from ObjectInputStream
........
moveMouseByDelta(dx, dy);
}
...........
}
private void moveMouseByDelta(int dx, int dy)
{
try {
Point p = MouseInfo.getPointerInfo().getLocation();
int currentX = p.x;
int currentY = p.y;
Robot robot = new Robot();
robot.mouseMove(currentX + dx, currentY + dy);
} catch (AWTException e) {
e.printStackTrace();
}
}
My Client (Android remote app):
private void touchTouchPad(MotionEvent event)
{
int x = (int)event.getX();
int y = (int)event.getY();
switch(event.getAction()) {
............
case MotionEvent.ACTION_MOVE:
if(leftMouseHold) {
if(clientThread != null) {
int dx = x - xMouse;
int dy = y - yMouse;
xMouse += dx;
yMouse += dy;
clientThread.sendDelta(dx, dy);
}
}
break;
..............
}
}
(This is not my homework, it is my study)
Edit: add more information
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只谈论 Windows 操作系统,这没什么不寻常的,因为 RDP 的带宽限制为 56-64Kb/秒,
1/冻结,减速和延迟是由分辨率之间的转换引起的(以方便的 480x320 和全高清 PC 显示器之间的像素为单位) )的两个设备,如果差异(以像素为单位)越大,那么运动就越不自然,
2/冻结和延迟是由数据连接的波动引起的,
最糟糕的是当它们此刻这两个因素在一起时,那么这很有趣
I speak only about Windows OS, this is nothing unusual, because RDP is limited to BW at 56-64Kb/per sec,
1 / freezing, slowdown and delay is caused by translation between resolution (in pixels between f.e. handy 480x320 and fullHD PC monitor) of both devices, if is the difference (in pixels) is greater, then the movement is more unnatural,
2 / freezing and delay is caused by fluctuations in the data connection
worst is when they are at the moment the two factors together, then it's decent fun