Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6412281

Robot.mouseMove(int, int) moves mouse pointer to incorrect position, Vista

XMLWordPrintable

    • x86
    • windows_vista

      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

            dcherepanov Dmitry Cherepanov
            dcherepanov Dmitry Cherepanov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: