坐标系似乎如下:x = 0,y = 0是主监视器的左上角.正X从左向右移动.正Y从上到下移动. (非常典型)
(顺便说一下,你应该使用screenSizes = get(0,’MonitorPositions’)而不是screenize,因为它可以正确处理多个监视器.)
以下命令对我有用:
%Setup
robot = java.awt.Robot;
screenSizes = get(0, 'MonitorPositions');
%Mouse to upper left of primary monitor
robot.mouseMove(1, 1)
%Mouse to center of primary monitor
robot.mouseMove(mean(screenSizes(1,[1 3])),mean(screenSizes(1,[2 4])))
%Mouse to hardcoded point 200 pixels down and 500 pixels to the right
robot.mouseMove(500, 200)
%Slow horizontal drag
for ix = 1:500
robot.mouseMove(ix, 200);
pause(0.01)
end
顺便提一下,您发布的代码似乎对我有用,将鼠标从左上角向右下角移动.所以很遗憾,上面的代码(对我有用)可能会遇到你原来遇到的问题. FWIW,我的版本信息是:
MATLAB Version 7.12.0.635 (R2011a)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.6.0_31-b05 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode