参考:Java-随机滑动鼠标和点击_胡安民的博客-CSDN博客_java移动鼠标点击
import java.awt.*;
public class MouseTest {
private Dimension dim; //存储屏幕尺寸
private Robot robot;//自动化对象
public MouseTest() {
dim = Toolkit.getDefaultToolkit().getScreenSize();
System.out.println("屏幕大小为:" + dim.getWidth() + " " + dim.getHeight());
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
public void Move(int width, int heigh) { //鼠标移动函数
System.out.println("enter Move()...");
try {
robot.delay(60000);
Point mousepoint = MouseInfo.getPointerInfo().getLocation();
System.out.println("移动前坐标:" + mousepoint.x + " " + mousepoint.y);
width += mousepoint.x;
heigh += mousepoint.y;
robot.mouseMove(width, heigh);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("移动后坐标:" + width + " " + heigh);
//robot.mousePress(InputEvent.BUTTON1_MASK);//鼠标单击
}
public static void main(String args[]) throws Exception {
MouseTest mmc = new MouseTest();
int min = 60;
for (int i = 0; i < min; i++) {
System.out.println("=======第" + i + "次移动=======");
System.out.println("mouse control start:");
mmc.Move(1, 1);//坐标为相对坐标
System.out.println("mouse control stop.");
}
}文章来源:https://www.toymoban.com/news/detail-630891.html
}文章来源地址https://www.toymoban.com/news/detail-630891.html
到了这里,关于Java 后端实现鼠标滚动,点击事件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!