Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Move mouse between monitors with java.awt.Robot

1 vue (au cours des 30 derniers jours)
Daniel Gordon
Daniel Gordon le 8 Mar 2019
Clôturé : Sabin le 19 Déc 2022
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

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by