上传备份

master
王兵 3 weeks ago
parent 3af8a16816
commit 87b19bd943

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -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;
}
/**
*
*

@ -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");
}
}
}

@ -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;
/**
*
* <p>
*
* <p>
*
* something#L0,0.png
* something
* #L0,0location
*
* @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;
}
}

@ -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();
}
});

@ -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<File> files = FileUtil.loopFiles(Legend.getDefaultBase(), pathname -> pathname.getName().startsWith(prefix));
if (files.size() > 0) {
DialogUtil.confirm("提示", "存在相同图例,是否旧的删除?", result -> {
if (result) {
for (File file1 : files) {
boolean delete = file1.delete();
if (!delete) {
Logger.info("删除失败,{}", file1.getAbsolutePath());
}
}
}
});
File selectedFile = jFileChooser.getSelectedFile();
String legendName = selectedFile.getName();
if (!legendName.endsWith(".png")) {
legendName += ".png";
}
// 图例文件名
filename = StrUtil.format("{}#{}.png", legendName, location);
file = new File(file.getParent(), filename);
File parentDir = selectedFile.getParentFile();
String finalLegendName = legendName;
Logger.info("保存路径" + file);
ImgUtil.cut(capture, file, new Rectangle(getCaptureX(), getCaptureY(), getCaptureWidth(), getCaptureHeight()));
// 提取公共的保存逻辑
Runnable saveAction = () -> {
File targetFile = new File(parentDir, finalLegendName);
doSave(targetFile);
close();
};
preferences.put(LAST_PATH, file.getParent());
Logger.info("保存目录" + file.getParent());
Logger.info("保存地址" + file);
List<File> existingFiles = FileUtil.loopFiles(Legend.getDefaultBase(),
pathname -> pathname.getName().equals(finalLegendName));
if (existingFiles.isEmpty()) {
saveAction.run();
} else {
DialogUtil.confirm("提示", "存在相同图例,是否覆盖?", result -> {
if (result) {
saveAction.run();
} else {
close(); // 用户取消时也关闭窗口
}
});
}
} else {
close(); // 用户取消选择时关闭窗口
}
close();
}
private void doSave(File targetFile) {
Logger.info("↓↓↓↓↓区域采集↓↓↓↓↓");
Logger.info("图例名称:{}", targetFile.getName().replaceAll("\\.png",""));
Logger.info("保存路径 {}", targetFile);
ImgUtil.cut(capture, targetFile, new Rectangle(
getCaptureX(),
getCaptureY(),
getCaptureWidth(),
getCaptureHeight()
));
preferences.put(LAST_PATH, targetFile.getParent());
Logger.info("保存目录 {}", targetFile.getParent());
Logger.info("保存地址 {}", targetFile);
Logger.info("用法示例:");
Logger.info("查找图例findLegend(\"{}\", 0.9)",targetFile.getName().replaceAll("\\.png",""));
Logger.info("");
Logger.info("↑↑↑↑↑区域采集↑↑↑↑↑");
}
public void close() {

@ -99,7 +99,7 @@ public class PickPoint extends JFrame {
super.mouseReleased(e);
x = e.getX();
y = e.getY();
Logger.info("=========================坐标采集=========================");
Logger.info("↓↓↓↓↓坐标采集↓↓↓↓↓");
Logger.info("屏幕坐标:[{},{}]", x, y);
Logger.info("相对坐标:[{},{}]", x - originX, y - originY);
String hexColor = Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF);
@ -108,7 +108,7 @@ public class PickPoint extends JFrame {
Logger.info("用法示例:");
Logger.info("1、点击坐标macro.mouseLeftClick(macro.of({},{}));", x - originX, y - originY);
Logger.info("2、色值比对macro.matchColor(macro.of({},{},\"#{}\"));", x - originX, y - originY, hexColor);
Logger.info("=========================坐标采集=========================");
Logger.info("↑↑↑↑↑坐标采集↑↑↑↑↑");
close();
JOptionPane.showMessageDialog(null, StrUtil.format("屏幕坐标:[{},{}]\n相对坐标[{},{}]\n坐标色值[#{}]", x, y, x - originX, y - originY, hexColor), "坐标信息", 1);

@ -117,7 +117,7 @@ public class PickRect extends JFrame {
int top = getCaptureY();
int right = getCaptureX() + getCaptureWidth();
int bottom = getCaptureY() + getCaptureHeight();
Logger.info("=========================区域采集=========================");
Logger.info("↓↓↓↓↓区域采集↓↓↓↓↓");
Logger.info("屏幕区域:[{},{},{},{}]", left, top, right, bottom);
Logger.info("相对区域:[{},{},{},{}]", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("-------------------");
@ -155,7 +155,7 @@ public class PickRect extends JFrame {
Logger.info("区域查色macro.findColor(macro.of({},{},{},{}), \"{}\");", left - originX, top - originY, right - originX, bottom - originY, topColor.get(0));
Logger.info("区域找色macro.hasColor(macro.of({},{},{},{}), \"{}\");", left - originX, top - originY, right - originX, bottom - originY, String.join("\",\"", topColor));
Logger.info("=========================区域采集=========================");
Logger.info("↑↑↑↑↑区域采集↑↑↑↑↑");
close();
}
});

@ -24,6 +24,7 @@ public class Logger {
String level = Level.INFO.toString();
// 格式化日志信息
String log = StrUtil.format(format, arg);
System.out.println(log);
// 获取调用者类名
String name = CallerUtil.getCallerCaller().getSimpleName();
// 获取当前线程的堆栈追踪

@ -35,7 +35,7 @@ public class TaskImpl extends JMacro {
return;
}
Logger.info("启动图标坐标:", launch.toString());
Logger.info("启动图标坐标:{}", launch.getRect().toString());
Logger.info("移动鼠标");
mouseMove(launch.getCenter());
Logger.info("双击我的电脑");

Loading…
Cancel
Save

Powered by TurnKey Linux.