Info

此问题已关闭。 请重新打开它进行编辑或回答。

Move mouse between monitors with java.awt.Robot

1 次查看(过去 30 天)
Hi,
I'm automating a process making use of the java.awt.Robot class to move the mouse. However, I've run in to an issue with my multi-monitor setup. Consider this code:
mouse = java.awt.Robot();
mouse.mouseMove(0, 0);
When this runs, the mouse cursor moves to the top left of the monitor that it's currently on when the code is run. To get around this, I tried adding the following:
screens = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
mouse = java.awt.Robot(screens(1));
mouse.mouseMove(0, 0);
I expected that following this change the mouse would only move to the origin of whichever screen corresponds to the first element of the screens array. However, this is not the case, and I see the exact same behaviour that the origin is relative to where the mouse is when running the code. Adding the screen input to the constructor seems to have not changed the behaviour as I expected (see documentation below).
I would be greatful for any help from someone familiar with using these java classes in Matlab.
Cheers

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by