parent
15bb5d817e
commit
ce19710a0c
@ -0,0 +1,66 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AliAccessStaticViaInstance" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AliDeprecation" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AliEqualsAvoidNull" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AliMissingOverrideAnnotation" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AliWrapperTypeEquality" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAbstractClassShouldStartWithAbstractNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidApacheBeanUtilsCopy" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidCallStaticSimpleDateFormat" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidCommentBehindStatement" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidComplexCondition" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidConcurrentCompetitionRandom" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidDoubleOrFloatEqualCompare" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidManuallyCreateThread" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidMissUseOfMathRandom" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidNegationOperator" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidNewDateGetTime" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidPatternCompileInMethod" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidReturnInFinally" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidStartWithDollarAndUnderLineNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaAvoidUseTimer" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaBigDecimalAvoidDoubleConstructor" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaBooleanPropertyShouldNotStartWithIs" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaClassCastExceptionWithSubListToArrayList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaClassCastExceptionWithToArray" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaClassMustHaveAuthor" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaClassNamingShouldBeCamel" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaCollectionInitShouldAssignCapacity" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaCommentsMustBeJavadocFormat" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaConcurrentExceptionWithModifyOriginSubList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaConstantFieldShouldBeUpperCase" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaCountDownShouldInFinally" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaDontModifyInForeachCircle" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaEnumConstantsMustHaveComment" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaExceptionClassShouldEndWithException" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaIbatisMethodQueryForList" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaLockShouldWithTryFinally" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaLowerCamelCaseVariableNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaMethodReturnWrapperType" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaMethodTooLong" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaPackageNaming" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaPojoMustOverrideToString" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaPojoMustUsePrimitiveField" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaPojoNoDefaultValue" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaRemoveCommentedCode" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaServiceOrDaoClassShouldEndWithImpl" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaStringConcat" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaSwitchStatement" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaTestClassShouldEndWithTestNaming" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaThreadLocalShouldRemove" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaThreadPoolCreation" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaThreadShouldSetName" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaTransactionMustHaveRollback" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaUndefineMagicConstant" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaUnsupportedExceptionWithModifyAsList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaUseQuietReferenceNotation" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||
<inspection_tool class="AlibabaUseRightCaseForDateFormat" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SmartFoxProjectConfig">
|
||||
<option name="projectInspectionClosed" value="true" />
|
||||
</component>
|
||||
</project>
|
Before Width: | Height: | Size: 323 KiB |
Before Width: | Height: | Size: 398 B After Width: | Height: | Size: 398 B |
After Width: | Height: | Size: 2.5 KiB |
@ -1,58 +0,0 @@
|
||||
//package com.example.jmacro;
|
||||
//
|
||||
//import java.awt.AWTException;
|
||||
//import java.awt.Point;
|
||||
//import java.awt.Rectangle;
|
||||
//import java.awt.Toolkit;
|
||||
//import java.awt.image.BufferedImage;
|
||||
//
|
||||
//public class CutImageTool {
|
||||
//
|
||||
// /**
|
||||
// * 截取指定左上角坐标,右下角坐标的屏幕区域图像
|
||||
// */
|
||||
// public static BufferedImage getScreeImage(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws AWTException {
|
||||
// int width = bottomRightX - topLeftX;
|
||||
// int height = bottomRightY - topLeftY;
|
||||
// Rectangle rectangle = new Rectangle(topLeftX, topLeftY, width, height);
|
||||
// return CommonUtil.getRobot().createScreenCapture(rectangle);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 截取指定左上角坐标,右下角坐标的屏幕区域图像
|
||||
// * @param topLeft
|
||||
// * @param bottomRight
|
||||
// * @return
|
||||
// * @throws AWTException
|
||||
// */
|
||||
// public static BufferedImage getScreeImage(Point topLeft, Point bottomRight) throws AWTException {
|
||||
// int X = topLeft.x;
|
||||
// int Y = topLeft.y;
|
||||
// int width = bottomRight.x - topLeft.x;
|
||||
// int height = bottomRight.y - topLeft.y;
|
||||
// Rectangle rectangle = new Rectangle(X, Y, width, height);
|
||||
// return CommonUtil.getRobot().createScreenCapture(rectangle);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 截取指定屏幕区域图像
|
||||
// * @param topLeft
|
||||
// * @param bottomRight
|
||||
// * @return
|
||||
// * @throws AWTException
|
||||
// */
|
||||
// public static BufferedImage getScreeImage(Rectangle rectangle) throws AWTException {
|
||||
// return CommonUtil.getRobot().createScreenCapture(rectangle);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 截取全屏幕图像
|
||||
// * @return
|
||||
// * @throws AWTException
|
||||
// */
|
||||
// public static BufferedImage getFullScreeImage() throws AWTException {
|
||||
// Rectangle rectangle = new Rectangle(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
|
||||
// return CommonUtil.getRobot().createScreenCapture(rectangle);
|
||||
// }
|
||||
//}
|
||||
//
|
@ -1,24 +1,199 @@
|
||||
package com.example.jmacro;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.example.jmacro.base.ScreenPoint;
|
||||
import com.example.jmacro.base.ScreenRect;
|
||||
import com.example.jmacro.util.ColorUtil;
|
||||
import com.example.jmacro.util.Imager;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 脚本
|
||||
* Java脚本
|
||||
*/
|
||||
public class JMacro {
|
||||
|
||||
/**
|
||||
* 图例位置
|
||||
* 机器人
|
||||
*/
|
||||
private Robot robot;
|
||||
|
||||
public JMacro() throws AWTException {
|
||||
this.robot = new Robot();
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标左键单击
|
||||
*
|
||||
* @param point 屏幕点
|
||||
*/
|
||||
public void mouseMove(ScreenPoint point) {
|
||||
waitTap();
|
||||
robot.mouseMove(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标左键单击
|
||||
*
|
||||
* @param rect 矩形区域
|
||||
*/
|
||||
public void mouseLeftClick(ScreenRect rect) {
|
||||
waitTap();
|
||||
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
||||
waitTap();
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
waitTap();
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标滚轮单击
|
||||
*
|
||||
* @param rect 矩形区域
|
||||
*/
|
||||
public void mouseWheelClick(ScreenRect rect) {
|
||||
waitTap();
|
||||
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
||||
waitTap();
|
||||
robot.mousePress(InputEvent.BUTTON2_MASK);
|
||||
waitTap();
|
||||
robot.mouseRelease(InputEvent.BUTTON2_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标右键单击
|
||||
*
|
||||
* @param rect 矩形区域
|
||||
*/
|
||||
public void mouseRightClick(ScreenRect rect) {
|
||||
waitTap();
|
||||
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
||||
waitTap();
|
||||
robot.mousePress(InputEvent.BUTTON3_MASK);
|
||||
waitTap();
|
||||
robot.mouseRelease(InputEvent.BUTTON3_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 鼠标左键双击
|
||||
*
|
||||
* @param rect 矩形区域
|
||||
*/
|
||||
public void mouseLeftDoubleClick(ScreenRect rect) {
|
||||
waitTap();
|
||||
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
||||
waitTap();
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
waitTap();
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
waitTap();
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
waitTap();
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 捕获指定区域屏幕
|
||||
*/
|
||||
public BufferedImage capture(Robot robot, ScreenRect screenRect) {
|
||||
return robot.createScreenCapture(new Rectangle(screenRect.getLeft(), screenRect.getTop(), screenRect.getWidth(), screenRect.getHeight()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕范围
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private File legend;
|
||||
public ScreenRect getScreenRect() {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
return new ScreenRect(0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
|
||||
}
|
||||
|
||||
public JMacro() {
|
||||
/**
|
||||
* 全屏查找图片
|
||||
*
|
||||
* @param pic 图片
|
||||
* @param minSimilar 最低相似度
|
||||
* @return 匹配的图片区域
|
||||
*/
|
||||
public ScreenRect findPic(File pic, double minSimilar) {
|
||||
return findPic(getScreenRect(), Imager.load(pic), minSimilar);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位
|
||||
* 全屏查找图片
|
||||
*
|
||||
* @param pic 图片
|
||||
* @param minSimilar 最低相似度
|
||||
* @return 匹配的图片区域
|
||||
*/
|
||||
private boolean location(){
|
||||
public ScreenRect findPic(BufferedImage pic, double minSimilar) {
|
||||
return findPic(getScreenRect(), pic, minSimilar);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取定位
|
||||
*
|
||||
* @param pic 参考图
|
||||
* @param screenRect 查找范围
|
||||
* @param minSimilar 相似度
|
||||
* @return
|
||||
*/
|
||||
public ScreenRect findPic(ScreenRect screenRect, BufferedImage pic, double minSimilar) {
|
||||
// 当查找区域比图片还小时,直接返回失败
|
||||
if (screenRect.getWidth() < pic.getHeight() || screenRect.getHeight() < pic.getHeight()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取实时屏幕
|
||||
BufferedImage screen = capture(robot, screenRect);
|
||||
int[][] screenData = Imager.getImageRGB(screen);
|
||||
int[][] picData = Imager.getImageRGB(pic);
|
||||
|
||||
// 得到图片左上角范围
|
||||
int xMin = screenRect.getLeft();
|
||||
int xMax = screenRect.getRight() - pic.getWidth();
|
||||
int yMin = screenRect.getTop();
|
||||
int yMax = screenRect.getBottom() - pic.getHeight();
|
||||
|
||||
for (int y = yMin; y <= yMax; y++) {
|
||||
for (int x = xMin; x <= xMax; x++) {
|
||||
// 对关键点进行先期匹配,降低运算复杂度。如果关键点本身就不匹配,就没必要再去匹配小图的每一个像素点
|
||||
// 左上角
|
||||
boolean lt = ColorUtil.isSimilar(screenData[x][y], picData[0][0]);
|
||||
// 右上角
|
||||
boolean rt = ColorUtil.isSimilar(screenData[x + pic.getWidth() - 1][y], picData[pic.getWidth() - 1][0]);
|
||||
// 左下角
|
||||
boolean lb = ColorUtil.isSimilar(screenData[x][y + pic.getHeight() - 1], picData[0][pic.getHeight() - 1]);
|
||||
// 右下角
|
||||
boolean rb = ColorUtil.isSimilar(screenData[x + pic.getWidth() - 1][y + pic.getHeight() - 1], picData[pic.getWidth() - 1][pic.getHeight() - 1]);
|
||||
//中心点
|
||||
boolean cc = ColorUtil.isSimilar(screenData[x + pic.getWidth() / 2][y + pic.getHeight() / 2], picData[pic.getWidth() / 2][pic.getHeight() / 2]);
|
||||
if (lt && rt && lb && rb && cc) {
|
||||
// 进行全像素匹配
|
||||
double similar = Imager.calcSimilar(x, y, pic.getHeight(), pic.getWidth(), screenData, picData);
|
||||
if (similar >= minSimilar) {
|
||||
return new ScreenRect(x, y, x + pic.getWidth(), y + pic.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void waitTap() {
|
||||
robot.delay(RandomUtil.randomInt(100, 200));
|
||||
}
|
||||
|
||||
public void waitNormal() {
|
||||
robot.delay(RandomUtil.randomInt(500, 1500));
|
||||
}
|
||||
|
||||
public void waitLong() {
|
||||
robot.delay(RandomUtil.randomInt(2000, 5000));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.example.jmacro.base;
|
||||
|
||||
/**
|
||||
* 屏幕点
|
||||
*/
|
||||
public class ScreenPoint {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public ScreenPoint() {
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.jmacro.base;
|
||||
|
||||
/**
|
||||
* 屏幕区域
|
||||
*/
|
||||
public class ScreenRect {
|
||||
|
||||
private int left;
|
||||
private int top;
|
||||
private int right;
|
||||
private int bottom;
|
||||
|
||||
public ScreenRect() {
|
||||
}
|
||||
|
||||
public ScreenRect(int left, int top, int right, int bottom) {
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.right = right;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.bottom - this.top;
|
||||
}
|
||||
|
||||
public int[] getCenter() {
|
||||
return new int[]{(left + right) / 2, (top + bottom) / 2};
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.example.jmacro;
|
||||
package com.example.jmacro.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
public class LogUtil {
|
||||
public class Logger {
|
||||
|
||||
public static void info(String log, Object... arg) {
|
||||
System.out.println(StrUtil.format(log, arg));
|
Loading…
Reference in new issue