Robot.mouseMove does not move to the specified location properly

Whenever I run a command mouseMovefor a robot, the mouse does not always go to the same place. For example, I have the following code:

import java.awt.Robot;
import java.util.concurrent.TimeUnit;

public class MainBot {
    public static void main(String[] args){
        try {
            Robot screenWin = new Robot();
            TimeUnit.SECONDS.sleep(2);
            screenWin.mouseMove(100, 300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The code usually causes the mouse to enter X:

Mouse location after launch First, I click run (I use eclipse) and move the mouse to the desired location (before the 2 second timer is set). Then the 2 second delay ends, and the mouse moves, and then the script ends. The problem is that the mouse never seems to go to the same place twice. For example, the mouse should go to (100, 300), but in most cases it looks more like (0, 300). In other cases, however, if I move the mouse at the beginning, where it should be approximately, then it goes to the right place.

, Paint, , , , .

-, , mouseMove?

: , , ( mouseMove ), mouseMove . , , .

+5

All Articles