上传备份

master
王兵 3 weeks ago
parent 7eb19cb562
commit 3af8a16816

@ -7,11 +7,11 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="starter-jmacro" />
<module name="jmacro" />
<module name="starter-jmacro-wjdr" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="jmacro" target="1.8" />
<module name="starter-jpg2mp4" target="1.8" />
</bytecodeTargetLevel>
</component>

@ -3,12 +3,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.wbsite</groupId>
<artifactId>jmacro</artifactId>
<artifactId>starter-jmacro</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<!--<packaging>war</packaging>--><!--需要打包成war时放开-->
<name>jmacro</name>
<description>project for jmacro</description>
<name>starter-jmacro</name>
<description>project for starter-jmacro</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -55,6 +54,12 @@
<artifactId>jintellitype</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<build>

File diff suppressed because it is too large Load Diff

@ -17,8 +17,8 @@ import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
import org.sikuli.script.Region;
import xyz.wbsite.jmacro.base.Legend;
import xyz.wbsite.jmacro.base.ViewRect;
import xyz.wbsite.jmacro.tool.Measure;
import xyz.wbsite.jmacro.tool.PickLegend;
import xyz.wbsite.jmacro.tool.PickPoint;
@ -99,13 +99,13 @@ public class JMainController implements Initializable {
*/
@FXML
public void pickPoint() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
Region screen = JMainService.getInstance().getMacro().getWorkRegion();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new PickPoint(screen.getLeft(), screen.getTop());
new PickPoint(screen.getX(), screen.getY());
} catch (AWTException awtException) {
awtException.printStackTrace();
}
@ -116,13 +116,13 @@ public class JMainController implements Initializable {
*/
@FXML
public void pickRect() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
Region screen = JMainService.getInstance().getMacro().getWorkRegion();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new PickRect(screen.getLeft(), screen.getTop());
new PickRect(screen.getX(), screen.getY());
} catch (AWTException awtException) {
awtException.printStackTrace();
}
@ -133,13 +133,13 @@ public class JMainController implements Initializable {
*/
@FXML
public void pickLegend() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
Region screen = JMainService.getInstance().getMacro().getWorkRegion();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new PickLegend(screen.getLeft(), screen.getTop(), Legend.getDefaultBase());
new PickLegend(screen.getX(), screen.getY(), Legend.getDefaultBase());
} catch (AWTException awtException) {
awtException.printStackTrace();
}
@ -150,13 +150,13 @@ public class JMainController implements Initializable {
*/
@FXML
public void measure() {
ViewRect screen = JMainService.getInstance().getMacro().getFocusRect();
Region screen = JMainService.getInstance().getMacro().getWorkRegion();
if (screen == null) {
DialogUtil.alert("未定位到视口,请稍后再试!");
return;
}
try {
new Measure(screen.getLeft(), screen.getTop());
new Measure(screen.getX(), screen.getY());
} catch (AWTException awtException) {
awtException.printStackTrace();
}

@ -69,7 +69,7 @@ public class JMainService {
}
public static boolean start() {
if (JMainService.getInstance().macro.getFocusRect() == null) {
if (JMainService.getInstance().macro.getWorkRegion() == null) {
JMainService.getInstance().macro.startFocus();
DialogUtil.alert("未聚焦到视口,请稍后再试!");
return false;

@ -0,0 +1,46 @@
package xyz.wbsite.jmacro.base;
import cn.hutool.core.util.StrUtil;
import org.sikuli.script.Location;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ColorLocation extends Location {
/**
*
*/
private String hexColor;
/**
* @param x
* @param y
* @param hexColor rgb #FFFFFF
*/
public ColorLocation(int x, int y, String hexColor) {
super(x, y);
this.hexColor = hexColor;
}
public ColorLocation(int x, int y, int hexColor) {
super(x, y);
this.hexColor = "#" + Integer.toHexString(hexColor);
}
public String getHexColor() {
return hexColor;
}
public void setHexColor(String hexColor) {
this.hexColor = hexColor;
}
public int getHexColorInt() {
return Integer.parseInt(StrUtil.removePrefix(hexColor, "#"), 16);
}
}

@ -5,6 +5,7 @@ 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;
@ -56,7 +57,7 @@ public class Legend {
/**
*
*/
private ViewPoint location;
private Location location;
public static void setDefaultBase(File base) {
defaultBase = base;
@ -98,7 +99,7 @@ public class Legend {
} 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 ViewPoint(x, y);
newLegend.location = new Location(x, y);
}
fileCache.put(name, newLegend);
@ -121,7 +122,7 @@ public class Legend {
return name;
}
public ViewPoint getLocation() {
public Location getLocation() {
return location;
}
}

@ -1,45 +0,0 @@
package xyz.wbsite.jmacro.base;
import cn.hutool.core.util.StrUtil;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ViewColor extends ViewPoint {
/**
*
*/
private int color;
/**
* @param x
* @param y
* @param hexColor rgb #FFFFFF
*/
public ViewColor(int x, int y, String hexColor) {
super(x, y);
this.color = Integer.parseInt(StrUtil.removePrefix(hexColor, "#"), 16);
}
public ViewColor(int x, int y, int color) {
super(x, y);
this.color = color;
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public String getHexColor() {
return "#" + Integer.toHexString(color);
}
}

@ -1,71 +0,0 @@
package xyz.wbsite.jmacro.base;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ViewPoint {
/**
* ()x
*/
private int x;
/**
* ()y
*/
private int y;
private ViewPoint() {
}
/**
*
*
* @param x x
* @param y y
*/
public ViewPoint(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public ViewPoint offset(int offsetX, int offsetY) {
return new ViewPoint(this.x + offsetX, this.y + offsetY);
}
public ViewPoint offsetX(int offsetX) {
return new ViewPoint(this.x + offsetX, this.y);
}
public ViewPoint offsetY(int offsetY) {
return new ViewPoint(this.x, this.y + offsetY);
}
@Override
public String toString() {
return "ViewPoint{" +
"x=" + x +
", y=" + y +
'}';
}
}

@ -1,105 +0,0 @@
package xyz.wbsite.jmacro.base;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ViewRect {
private int left;
private int top;
private int right;
private int bottom;
/**
*
*/
private double similar;
public ViewRect() {
}
public ViewRect(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public ViewRect(int left, int top, int right, int bottom, double similar) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
this.similar = similar;
}
public int getLeft() {
return left;
}
public void setLeft(int left) {
this.left = left;
}
public int getTop() {
return top;
}
public void setTop(int top) {
this.top = top;
}
public int getRight() {
return right;
}
public void setRight(int right) {
this.right = right;
}
public int getBottom() {
return bottom;
}
public void setBottom(int bottom) {
this.bottom = bottom;
}
public int getWidth() {
return this.right - this.left + 1;
}
public int getHeight() {
return this.bottom - this.top + 1;
}
public ViewPoint getCenter() {
return new ViewPoint((left + right) / 2, (top + bottom) / 2);
}
public ViewRect offset(int offsetX, int offsetY) {
return new ViewRect(this.left + offsetX, this.top + offsetY, this.right + offsetX, this.bottom + offsetY);
}
public ViewRect offsetX(int offsetX) {
return new ViewRect(this.left + offsetX, this.top, this.right + offsetX, this.bottom);
}
public ViewRect offsetY(int offsetY) {
return new ViewRect(this.left, this.top + offsetY, this.right, this.bottom + offsetY);
}
@Override
public String toString() {
return "ViewRect{" +
"left=" + left +
", top=" + top +
", right=" + right +
", bottom=" + bottom +
'}';
}
}

@ -3,8 +3,6 @@ package xyz.wbsite.jmacro.util;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.IoUtil;
import xyz.wbsite.jmacro.JMainApplication;
import xyz.wbsite.jmacro.JMainService;
import xyz.wbsite.jmacro.base.ViewRect;
import java.awt.*;
import java.awt.image.BufferedImage;
@ -109,17 +107,6 @@ public class ImageUtil {
return (double) similar / (smallWidth * smallHeight);
}
/**
*
*
* @param rect
*/
public static void show(ViewRect rect) {
Robot robot = JMainService.getInstance().getMacro().getRobot();
BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()));
show(screenCapture);
}
/**
*
*

@ -1,7 +1,7 @@
package xyz.wbsite.jtask;
import org.sikuli.script.Region;
import xyz.wbsite.jmacro.JMacro;
import xyz.wbsite.jmacro.base.ViewRect;
import xyz.wbsite.jmacro.util.Logger;
/**
@ -14,11 +14,11 @@ import xyz.wbsite.jmacro.util.Logger;
public class TaskImpl extends JMacro {
@Override
public synchronized ViewRect focus() {
public synchronized Region focus() {
Logger.info("定位工作窗口");
ViewRect rect = getScreenRect();
Region rect = getScreenRect();
Logger.info("聚焦窗口:" + rect.toString());
Logger.info("聚焦窗口大小:{}x{}", rect.getRight() - rect.getLeft(), rect.getBottom() - rect.getTop());
Logger.info("聚焦窗口大小:{}x{}", rect.getW(), rect.getH());
return rect;
}
@ -29,7 +29,7 @@ public class TaskImpl extends JMacro {
Logger.info("启动任务");
Logger.info("查找我的电脑图标");
ViewRect launch = findLegend("我的电脑", 0.9);
Region launch = findLegend("我的电脑", 0.9);
if (launch == null) {
Logger.error("未找到我的电脑图标");
return;
@ -37,24 +37,24 @@ public class TaskImpl extends JMacro {
Logger.info("启动图标坐标:", launch.toString());
Logger.info("移动鼠标");
mouseMove(launch.getCenter(), true);
mouseMove(launch.getCenter());
Logger.info("双击我的电脑");
mouseLeftDoubleClick(launch);
Logger.info("等待程序启动中,请稍等...");
delay(3 * 1000);
ViewRect windows = findLegend("我的电脑窗口", 0.9);
Region windows = findLegend("我的电脑窗口", 0.9);
if (windows == null) {
Logger.error("我的电脑启动失败");
return;
}
Logger.info("定位到我的电脑窗口");
Logger.info("移动鼠标");
mouseMove(windows.getCenter().offsetX(100), true);
mouseMove(windows.getCenter().offset(100,0));
Logger.info("等待1秒后自动关闭");
delay(1000);
mouseLeftClick(windows.getCenter().offsetX(100));
mouseLeftClick(windows.getCenter().offset(100,0));
Logger.info("结束任务");
}

Loading…
Cancel
Save

Powered by TurnKey Linux.