Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move cursor more smoothly (remote app)

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

like image 781
emeraldhieu Avatar asked Nov 14 '22 23:11

emeraldhieu


1 Answers

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

like image 53
mKorbel Avatar answered Dec 16 '22 10:12

mKorbel