JDK-6412281 : Robot.mouseMove(int, int) moves mouse pointer to incorrect position, Vista
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2006-04-12
  • Updated: 2011-01-19
  • Resolved: 2006-06-30
Related Reports
Duplicate :  
Description
Use the test case below to reproduce this bug.

In the test case robot will move mouse pointer to given screen coordinates (button's top-left corner). After that we retrieve mouse location using MouseInfo.getPointerInfo(). You will see that this location will be different from the initially given coordinates. Moreover, it possible to observe that mouse will be placed higher that top-left corner of button.

Not reproducible on XP.

============================ TEST CASE =============
import java.awt.*;
import java.awt.event.*;
import java.security.*;

public class testcase{
    final static Button button = new Button("button");

    public static final void main(String args[]){
        Frame frame = new Frame("frame");

        frame.setLayout(new FlowLayout());
        frame.add(button);
        frame.setBounds(100,100,100,100);
        frame.setVisible(true);

        (new Thread(){
                public void run(){
                    try{
                        Thread.sleep(1000);
                        Robot robot = new Robot();
                        Point point = button.getLocationOnScreen();
                        System.out.println("* move to (x,y): "+point.x+","+point.y);
                        robot.mouseMove(point.x, point.y);
                        robot.delay(100);
                        Point pointer = (Point)AccessController.doPrivileged(new PrivilegedAction() {
                                public Object run() {
                                    return MouseInfo.getPointerInfo().getLocation();
                                }
                            });
                        System.out.println("* pointerinfo (x,y):"+pointer.x+","+pointer.y);
                    }catch(Exception e){
                        System.out.println(e);
                    }
                }
            }).start();
    }
}
reproducible with dpi setting - 120 pixels per inch

Comments
EVALUATION This isuue is reproducible on Vista only if checkbox 'Use Windows XP style DPI scaling' is disabled. I've verified that the testcase passes since JDK6.0 b86.
30-06-2006

EVALUATION The cause is dpi scaling by the window manager (see 6395346 for more information).
14-04-2006