diff --git a/legend/我的电脑#L22,10.png b/legend/我的电脑#L22,10.png deleted file mode 100644 index 1288d9b..0000000 Binary files a/legend/我的电脑#L22,10.png and /dev/null differ diff --git a/legend/我的电脑.png b/legend/我的电脑.png new file mode 100644 index 0000000..e0363db Binary files /dev/null and b/legend/我的电脑.png differ diff --git a/legend/我的电脑窗口#L409,528.png b/legend/我的电脑窗口.png similarity index 100% rename from legend/我的电脑窗口#L409,528.png rename to legend/我的电脑窗口.png diff --git a/src/main/java/xyz/wbsite/jmacro/JMacro.java b/src/main/java/xyz/wbsite/jmacro/JMacro.java index 6fdc8b9..4ed6367 100644 --- a/src/main/java/xyz/wbsite/jmacro/JMacro.java +++ b/src/main/java/xyz/wbsite/jmacro/JMacro.java @@ -178,8 +178,8 @@ public abstract class JMacro { * 鼠标左键双击 */ public void mouseLeftDoubleClick(Region region) { - Mouse.move(new Location(region.getX(), region.getY())); - Mouse.at().click(); + Mouse.move(region.getCenter()); + Mouse.at().doubleClick(); } /** @@ -187,7 +187,7 @@ public abstract class JMacro { */ public void mouseLeftDoubleClick(Location location) { Mouse.move(location); - Mouse.at().click(); + Mouse.at().doubleClick(); } /** @@ -335,6 +335,24 @@ public abstract class JMacro { return new Region(match.getRect()); } + /** + * 查找并点击图例 + * + * @param legend 图例 + * @param minSimilar 最低相似度 + * @return 匹配区域 + */ + public boolean clickLegend(String legend, double minSimilar) { + Pattern pattern = new Pattern(of(legend).getFile().getAbsolutePath()) + .similar(minSimilar); + Match match = workRegion.findBest(pattern); + if (match == null) { + return false; + } + mouseLeftClick(match.getCenter()); + return true; + } + /** * 获取图例 * diff --git a/src/main/java/xyz/wbsite/jmacro/JRoot.java b/src/main/java/xyz/wbsite/jmacro/JRoot.java deleted file mode 100644 index 98d77ff..0000000 --- a/src/main/java/xyz/wbsite/jmacro/JRoot.java +++ /dev/null @@ -1,39 +0,0 @@ -package xyz.wbsite.jmacro; - -import java.awt.*; - -/** - * 重写系统Robot类的部分方法 - */ -public class JRoot extends Robot { - - private static final int MAX_DELAY = 60000; - - public JRoot() throws AWTException { - } - - public JRoot(GraphicsDevice screen) throws AWTException { - super(screen); - } - - /** - * 需要主动将线程中断异常抛出去 - * - * @param ms 毫秒 - */ - @Override - public synchronized void delay(int ms) { - checkDelayArgument(ms); - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - private void checkDelayArgument(int ms) { - if (ms < 0 || ms > MAX_DELAY) { - throw new IllegalArgumentException("Delay must be to 0 to 60,000ms"); - } - } -} diff --git a/src/main/java/xyz/wbsite/jmacro/base/Legend.java b/src/main/java/xyz/wbsite/jmacro/base/Legend.java index 2c002b0..8dc629e 100644 --- a/src/main/java/xyz/wbsite/jmacro/base/Legend.java +++ b/src/main/java/xyz/wbsite/jmacro/base/Legend.java @@ -2,10 +2,7 @@ package xyz.wbsite.jmacro.base; import cn.hutool.cache.Cache; import cn.hutool.cache.CacheUtil; -import cn.hutool.core.convert.Convert; import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ReUtil; -import org.sikuli.script.Location; import xyz.wbsite.jmacro.util.ImageUtil; import xyz.wbsite.jmacro.util.Logger; @@ -15,13 +12,6 @@ import java.util.List; /** * 图例 - *
- * 图例分带坐标和不带坐标图例 - *
- * 其中带坐标图例,通过将坐标融合进文件名称实现,定义如下
- * 以something#L0,0.png为例
- * 图例名称:something
- * 图例坐标:#L0,0(在实例化时转为location)
*
* @author wangbing
* @version 0.0.1
@@ -54,11 +44,6 @@ public class Legend {
*/
private String name;
- /**
- * 图例坐标
- */
- private Location location;
-
public static void setDefaultBase(File base) {
defaultBase = base;
}
@@ -93,15 +78,6 @@ public class Legend {
newLegend.base = defaultBase;
newLegend.file = file;
newLegend.name = name;
-
- if (!file.getName().matches("[\\S\\s]+#L[0-9]+,[0-9]+\\.png")) {
- newLegend.location = null;
- } else {
- int x = Convert.toInt(ReUtil.get("[\\S\\s]+#L([0-9]+),[0-9]+\\.png", file.getName(), 1), 0);
- int y = Convert.toInt(ReUtil.get("[\\S\\s]+#L[0-9]+,([0-9]+)\\.png", file.getName(), 1), 0);
- newLegend.location = new Location(x, y);
- }
-
fileCache.put(name, newLegend);
return newLegend;
}
@@ -121,8 +97,4 @@ public class Legend {
public String getName() {
return name;
}
-
- public Location getLocation() {
- return location;
- }
}
diff --git a/src/main/java/xyz/wbsite/jmacro/tool/Measure.java b/src/main/java/xyz/wbsite/jmacro/tool/Measure.java
index f66428f..bdd73e0 100644
--- a/src/main/java/xyz/wbsite/jmacro/tool/Measure.java
+++ b/src/main/java/xyz/wbsite/jmacro/tool/Measure.java
@@ -118,14 +118,12 @@ public class Measure extends JFrame {
int top = getCaptureY();
int right = getCaptureX() + getCaptureWidth();
int bottom = getCaptureY() + getCaptureHeight();
- Logger.info("=========================测量距离=========================");
+ Logger.info("↓↓↓↓↓测量距离↓↓↓↓↓");
Logger.info("水平距离:{}px", getCaptureWidth());
Logger.info("垂直距离:{}px", getCaptureHeight());
-
Logger.info("用法示例:");
Logger.info("1、区域点击:mouseLeftClick(of({},{},{},{}));", left - originX, top - originY, right - originX, bottom - originY);
-
- Logger.info("=========================测量距离=========================");
+ Logger.info("↑↑↑↑↑测量距离↑↑↑↑↑");
close();
}
});
diff --git a/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java b/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java
index e37452f..b88def6 100644
--- a/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java
+++ b/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java
@@ -11,10 +11,17 @@ import xyz.wbsite.jmacro.util.Logger;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
-import java.awt.event.*;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.prefs.Preferences;
/**
@@ -201,8 +208,7 @@ public class PickLegend extends JFrame {
// 上一次保存目录
String lastPath = preferences.get(LAST_PATH, "");
// 默认文件名
- String location = "L" + (getCaptureX() - originX) + "," + (getCaptureY() - originY);
- String filename = StrUtil.format("{}#{}.png", System.currentTimeMillis(), location);
+ String filename = StrUtil.format("{}.png", System.currentTimeMillis());
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setFileFilter(new FileNameExtensionFilter("png", "png"));
@@ -211,38 +217,61 @@ public class PickLegend extends JFrame {
jFileChooser.setSelectedFile(new File(filename));
int returnVal = jFileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
- // 默认文件
- File file = jFileChooser.getSelectedFile();
- String name = file.getName().replaceAll("\\.png", "");
- String legendName = name.split("#")[0];
- String prefix = legendName + "#";
-
- List