|
|
|
@ -108,15 +108,14 @@ public abstract class JMacro {
|
|
|
|
|
* @param smooth 平滑移动
|
|
|
|
|
*/
|
|
|
|
|
public void mouseMove(ViewPoint point, boolean smooth) {
|
|
|
|
|
int endX = point.getX() + (point.isAbsolute() ? 0 : getFocusRect().getLeft());
|
|
|
|
|
int endY = point.getY() + (point.isAbsolute() ? 0 : getFocusRect().getTop());
|
|
|
|
|
int endX = point.getX();
|
|
|
|
|
int endY = point.getY();
|
|
|
|
|
if (smooth) {
|
|
|
|
|
// 获取当前鼠标位置
|
|
|
|
|
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
|
|
|
|
|
int startX = mousePoint.x;
|
|
|
|
|
int startY = mousePoint.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 求两点距离
|
|
|
|
|
double absX = Math.abs(startX - endX);
|
|
|
|
|
double absY = Math.abs(startY - endY);
|
|
|
|
@ -156,7 +155,7 @@ public abstract class JMacro {
|
|
|
|
|
* @param rect 矩形区域
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftClick(ViewRect rect) {
|
|
|
|
|
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1], true));
|
|
|
|
|
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -178,11 +177,11 @@ public abstract class JMacro {
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftDrag(ViewPoint start, ViewPoint end, boolean smooth) {
|
|
|
|
|
mouseMove(start, smooth);
|
|
|
|
|
delayUnstable();
|
|
|
|
|
delay();
|
|
|
|
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
|
|
|
|
delayUnstable();
|
|
|
|
|
delay();
|
|
|
|
|
mouseMove(end, smooth);
|
|
|
|
|
delayUnstable();
|
|
|
|
|
delay();
|
|
|
|
|
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -347,6 +346,18 @@ public abstract class JMacro {
|
|
|
|
|
return findPic(getFocusRect(), pic, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param viewRect 查找范围(不设时,取全屏)
|
|
|
|
|
* @param pic 待查找图片
|
|
|
|
|
* @param minSimilar 相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, File pic, double minSimilar) {
|
|
|
|
|
return findPic(viewRect, ImageUtil.load(pic), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
@ -371,6 +382,7 @@ public abstract class JMacro {
|
|
|
|
|
|
|
|
|
|
// 获取实时屏幕
|
|
|
|
|
BufferedImage screen = capture(robot, viewRect);
|
|
|
|
|
ImageUtil.show(screen);
|
|
|
|
|
int[][] screenData = ImageUtil.getImageRGB(screen);
|
|
|
|
|
int[][] picData = ImageUtil.getImageRGB(pic);
|
|
|
|
|
|
|
|
|
@ -416,6 +428,72 @@ public abstract class JMacro {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(String legend, double minSimilar) {
|
|
|
|
|
return findLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return findPic(legend.getFile(), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, String legend, double minSimilar) {
|
|
|
|
|
return findLegend(rect, Legend.inflate(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, Legend legend, double minSimilar) {
|
|
|
|
|
return findPic(rect, legend.getFile(), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(legend.getFile(), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindLegend(ViewRect rect, Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(rect, legend.getFile(), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
*
|
|
|
|
@ -743,4 +821,46 @@ public abstract class JMacro {
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndMatchPic(legend.getFile(), legend.getLocation(), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为绝对坐标
|
|
|
|
|
*
|
|
|
|
|
* @return 绝对区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect of(int left, int top, int right, int bottom) {
|
|
|
|
|
int ox = getFocusRect().getLeft();
|
|
|
|
|
int oy = getFocusRect().getTop();
|
|
|
|
|
return new ViewRect(left + ox, top + oy, right + ox, bottom + oy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对区域转为绝对区域
|
|
|
|
|
*
|
|
|
|
|
* @param relativeRect 相对区域
|
|
|
|
|
* @return 绝对区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect of(ViewRect relativeRect) {
|
|
|
|
|
return new ViewRect(relativeRect.getLeft(), relativeRect.getTop(), relativeRect.getRight(), relativeRect.getBottom());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为绝对坐标
|
|
|
|
|
*
|
|
|
|
|
* @return 绝对坐标
|
|
|
|
|
*/
|
|
|
|
|
public ViewPoint of(int x, int y) {
|
|
|
|
|
int ox = getFocusRect().getLeft();
|
|
|
|
|
int oy = getFocusRect().getTop();
|
|
|
|
|
return new ViewPoint(x + ox, y + oy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为绝对坐标
|
|
|
|
|
*
|
|
|
|
|
* @param relativePoint 相对坐标
|
|
|
|
|
* @return 绝对区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewPoint of(ViewPoint relativePoint) {
|
|
|
|
|
return of(relativePoint.getX(), relativePoint.getY());
|
|
|
|
|
}
|
|
|
|
|
}
|