I am writing an Android application for Android. When I touch and move in the Android application, the cursor also moves on the server machine, but it pauses for about a second .
My application just has two streams: the client sends the coordinates, the server receives them and that's it. My solution is to simply pass dx, dy through an ObjectInputStream and use Robot :: mouseMove to move the cursor.
Can you give me some tips to prevent cursor lag? (seamlessly like RemoteDroid ^^)
My North:
public void run() {
..........
while(true) {
........
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 Android 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, this is my research)
Edit: add more information