Skip to content

Commit 57ce6e4

Browse files
committed
fix mouse position on multi monitor setups
fixes #29 (cherry picked from commit 3ebe105)
1 parent 3160a4c commit 57ce6e4

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

Customer/src/main/java/de/openindex/support/customer/CustomerApplication.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.awt.Desktop;
3838
import java.awt.GraphicsConfiguration;
3939
import java.awt.GraphicsDevice;
40+
import java.awt.Rectangle;
4041
import java.awt.event.ActionEvent;
4142
import java.awt.event.ActionListener;
4243
import java.awt.event.KeyEvent;
@@ -430,13 +431,14 @@ public void processReceivedObject(Serializable object) {
430431
} else if (object instanceof MouseMoveRequest) {
431432

432433
final MouseMoveRequest request = (MouseMoveRequest) object;
433-
final int x;
434-
final int y;
434+
final GraphicsConfiguration screenConfiguration = screen.getDefaultConfiguration();
435+
436+
int x;
437+
int y;
435438

436439
// On Windows systems we need to convert the coordinates
437440
// according to the current screen scaling factor.
438441
if (SystemUtils.IS_OS_WINDOWS) {
439-
final GraphicsConfiguration screenConfiguration = screen.getDefaultConfiguration();
440442
final AffineTransform transform = screenConfiguration.getDefaultTransform();
441443
final double scaleX = (transform != null && transform.getScaleX() > 0) ?
442444
transform.getScaleX() : 1;
@@ -450,6 +452,16 @@ public void processReceivedObject(Serializable object) {
450452
y = request.y;
451453
}
452454

455+
// Calculate absolute coordinates for the selected screen.
456+
// Required for multi monitor setups.
457+
Rectangle bounds = screenConfiguration.getBounds();
458+
//LOGGER.debug("screen bounds {} x {}", bounds.x, bounds.y);
459+
//LOGGER.debug("screen size {} x {}", bounds.width, bounds.height);
460+
//LOGGER.debug("mouse coords {} x {}", x, y);
461+
x += bounds.x;
462+
y += bounds.y;
463+
//LOGGER.debug("move mouse to {} x {}", x, y);
464+
453465
robot.mouseMove(x, y);
454466

455467
} else if (object instanceof MousePressRequest) {

0 commit comments

Comments
 (0)