3

I'm using Windows 10 on a Dell Inspiron 13 5000, a 13 inch laptop that has 1920 * 1080 pixels, using the laptop screen. Code:

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot = new Robot();
robot.mouseMove(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
//screenSize.getWidth() = 1920, getHeight() = 1080

But this doesn't move the mouse to the middle of the screen, it moves it further than the middle. Also when I go to https://www.whatismyscreenresolution.com/ it says my resolution is 1280 * 720. In settings however it says my resolution is 1920 * 1080. I want to run a program that is based on a 1920 * 1080 resolution. Why is this happening? I also tried this but it moves the pointer to less than the middle:

   robot.mouseMove(screensize.getWidth() / 2 * 1280 / 1920, screensize.getHeight() / 2 * 720 / 1080);

Is this a computer manufacturer problem? I turned screen scaling to 100% and screenSize.getWidth() = 2880, screenSize.getHeight() = 1620 which is weird.

Lesmana
  • 25,663
  • 9
  • 82
  • 87
dan dan
  • 475
  • 1
  • 3
  • 12
  • Please [take the tour](http://stackoverflow.com/tour) to see how the site works and what questions are on topic here, and [edit] your question accordingly. See also: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Joe C Dec 20 '17 at 21:56
  • It is a default comment when somebody edits/flags your answer during review. They might have found your question lacking detail, or found it off-topic for this site. Anyway... How far away from the middle are we talking about? Do you have scaling activated? Is 1920x1080 the size that `getScreenSize` actually returns (have you checked with debug/sysout)? – Malte Hartwig Dec 20 '17 at 22:08
  • oh i didnt know that and yes i checked and printed out screensize – dan dan Dec 20 '17 at 22:09
  • On my work laptop your code correctly centers the mouse both docked with multiple monitors, and undocked. I'm going to guess it's something weird about your specific computer. If it matters: I've got 125% scaling while undocked, and the whatismyscreenresolution.com correctly gets 1920x1080 for me. – azurefrog Dec 20 '17 at 22:12
  • What about screen scaling (Are you using windows)? [This old bug](https://bugs.openjdk.java.net/browse/JDK-6412281) describes similar errors. – Malte Hartwig Dec 20 '17 at 22:12
  • [This question](https://stackoverflow.com/questions/4707756/how-to-correctly-detect-dpi-of-display-with-java) talks about issues like yours. one of the comments proposes another way to retrieve the screen dimensions via `GraphicsEnvironment.getLocalGraphicsEnvironment().getDefault‌​ScreenDevice().getDi‌​splayMode()`. Also, [this answer](https://stackoverflow.com/a/47142985/7653073) sounds useful. – Malte Hartwig Dec 20 '17 at 22:26

0 Answers0