public class MouseControlsTools {
private static final Robot robot;
static {
try {
robot = new Robot();
} catch (AWTException e) {
throw new RuntimeException(e);
}
}
private static final List<Coord> coordList = new ArrayList<>() {{
add(new Coord(484, 184,2000));
add(new Coord(474, 223,2000));
add(new Coord(1698, 335,2000));
add(new Coord(194, 504,2000));
add(new Coord(191, 652,2000));
add(new Coord(402, 777,2000));
add(new Coord(203, 813,2000));
add(new Coord(1032, 956, 2000));
add(new Coord(1017, 641, 8000));
}};
public static void main(String[] args) throws Exception{
//操作的次数
int num = 2000;
for (int i = 0; i < num; i++) {
for (Coord coord : coordList) {
robot.mouseMove(coord.getX(), coord.getY()); // 移动鼠标到指定坐标
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放
//停顿时间
Thread.sleep(coord.getSleep());
}
}
}
}
@Data
class Coord {
//桌面的x/y轴坐标点
private int x;
private int y;
//等待时长 毫秒
private long sleep;
public Coord(int x, int y, long sleep) {
this.x = x;
this.y = y;
this.sleep = sleep;
}
public Coord() {
}
}
补充(可添加其他复杂操作,如粘贴复制)
// 获取系统剪贴板
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
//检查剪贴板中是否有文本内容
if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
// 获取剪贴板的文本内容
String text = (String) clipboard.getData(DataFlavor.stringFlavor);
}