w-mousekey 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/AutoHotkey_2.0.19/AutoHotkey.chm +0 -0
- package/AutoHotkey_2.0.19/AutoHotkey32.exe +0 -0
- package/AutoHotkey_2.0.19/AutoHotkey64.exe +0 -0
- package/AutoHotkey_2.0.19/Install.cmd +2 -0
- package/AutoHotkey_2.0.19/UX/Templates/Minimal for v2.ahk +6 -0
- package/AutoHotkey_2.0.19/UX/WindowSpy.ahk +246 -0
- package/AutoHotkey_2.0.19/UX/inc/CommandLineToArgs.ahk +12 -0
- package/AutoHotkey_2.0.19/UX/inc/CreateAppShortcut.ahk +37 -0
- package/AutoHotkey_2.0.19/UX/inc/EnableUIAccess.ahk +246 -0
- package/AutoHotkey_2.0.19/UX/inc/GetGitHubReleaseAssetURL.ahk +26 -0
- package/AutoHotkey_2.0.19/UX/inc/HashFile.ahk +96 -0
- package/AutoHotkey_2.0.19/UX/inc/README.txt +3 -0
- package/AutoHotkey_2.0.19/UX/inc/ShellRun.ahk +7 -0
- package/AutoHotkey_2.0.19/UX/inc/bounce-v1.ahk +3 -0
- package/AutoHotkey_2.0.19/UX/inc/common.ahk +21 -0
- package/AutoHotkey_2.0.19/UX/inc/config.ahk +13 -0
- package/AutoHotkey_2.0.19/UX/inc/identify.ahk +29 -0
- package/AutoHotkey_2.0.19/UX/inc/identify_regex.ahk +4 -0
- package/AutoHotkey_2.0.19/UX/inc/launcher-common.ahk +78 -0
- package/AutoHotkey_2.0.19/UX/inc/spy.ico +0 -0
- package/AutoHotkey_2.0.19/UX/inc/ui-base.ahk +129 -0
- package/AutoHotkey_2.0.19/UX/install-ahk2exe.ahk +53 -0
- package/AutoHotkey_2.0.19/UX/install-version.ahk +109 -0
- package/AutoHotkey_2.0.19/UX/install.ahk +1056 -0
- package/AutoHotkey_2.0.19/UX/launcher.ahk +430 -0
- package/AutoHotkey_2.0.19/UX/reload-v1.ahk +22 -0
- package/AutoHotkey_2.0.19/UX/reset-assoc.ahk +38 -0
- package/AutoHotkey_2.0.19/UX/ui-dash.ahk +200 -0
- package/AutoHotkey_2.0.19/UX/ui-editor.ahk +238 -0
- package/AutoHotkey_2.0.19/UX/ui-launcherconfig.ahk +195 -0
- package/AutoHotkey_2.0.19/UX/ui-newscript.ahk +296 -0
- package/AutoHotkey_2.0.19/UX/ui-setup.ahk +175 -0
- package/AutoHotkey_2.0.19/UX/ui-uninstall.ahk +68 -0
- package/AutoHotkey_2.0.19/WindowSpy.ahk +2 -0
- package/AutoHotkey_2.0.19/license.txt +351 -0
- package/AutoHotkey_2.0.19/zclick.ahk +5 -0
- package/AutoHotkey_2.0.19/zrun_click.bat +2 -0
- package/AutoHotkey_2.0.19/zrun_send.bat +2 -0
- package/AutoHotkey_2.0.19/zsend.ahk +4 -0
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/SECURITY.md +5 -0
- package/_tmp/view.all.png +0 -0
- package/_tmp/view.det.png +0 -0
- package/babel.config.js +16 -0
- package/dist/action.umd.js +32 -0
- package/dist/action.umd.js.map +1 -0
- package/dist/ck-pic.umd.js +7 -0
- package/dist/ck-pic.umd.js.map +1 -0
- package/dist/compare.umd.js +7 -0
- package/dist/compare.umd.js.map +1 -0
- package/dist/get-settings.umd.js +7 -0
- package/dist/get-settings.umd.js.map +1 -0
- package/dist/mousekey.umd.js +7 -0
- package/dist/mousekey.umd.js.map +1 -0
- package/dist/screen.umd.js +7 -0
- package/dist/screen.umd.js.map +1 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +84 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g.mjs +46 -0
- package/g.test_opencv.mjs +36 -0
- package/package.json +41 -0
- package/pic/view.png +0 -0
- package/script.txt +17 -0
- package/src/action.mjs +132 -0
- package/src/ckPic.mjs +95 -0
- package/src/compare.mjs +201 -0
- package/src/getSettings.mjs +17 -0
- package/src/mousekey.mjs +95 -0
- package/src/screen.mjs +62 -0
- package/test/WMousekey.test.mjs +11 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +33 -0
- package/toolg/modifyReadme.mjs +4 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.pln {
|
|
2
|
+
color: #ddd;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* string content */
|
|
6
|
+
.str {
|
|
7
|
+
color: #61ce3c;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* a keyword */
|
|
11
|
+
.kwd {
|
|
12
|
+
color: #fbde2d;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* a comment */
|
|
16
|
+
.com {
|
|
17
|
+
color: #aeaeae;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* a type name */
|
|
21
|
+
.typ {
|
|
22
|
+
color: #8da6ce;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* a literal value */
|
|
26
|
+
.lit {
|
|
27
|
+
color: #fbde2d;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* punctuation */
|
|
31
|
+
.pun {
|
|
32
|
+
color: #ddd;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* lisp open bracket */
|
|
36
|
+
.opn {
|
|
37
|
+
color: #000000;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* lisp close bracket */
|
|
41
|
+
.clo {
|
|
42
|
+
color: #000000;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* a markup tag name */
|
|
46
|
+
.tag {
|
|
47
|
+
color: #8da6ce;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* a markup attribute name */
|
|
51
|
+
.atn {
|
|
52
|
+
color: #fbde2d;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* a markup attribute value */
|
|
56
|
+
.atv {
|
|
57
|
+
color: #ddd;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* a declaration */
|
|
61
|
+
.dec {
|
|
62
|
+
color: #EF5050;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* a variable name */
|
|
66
|
+
.var {
|
|
67
|
+
color: #c82829;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* a function name */
|
|
71
|
+
.fun {
|
|
72
|
+
color: #4271ae;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Specify class=linenums on a pre to get line numbering */
|
|
76
|
+
ol.linenums {
|
|
77
|
+
margin-top: 0;
|
|
78
|
+
margin-bottom: 0;
|
|
79
|
+
padding-bottom: 2px;
|
|
80
|
+
}
|
package/g.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import mk from './src/mousekey.mjs'
|
|
3
|
+
import sc from './src/screen.mjs'
|
|
4
|
+
import cp from './src/compare.mjs'
|
|
5
|
+
import ckPic from './src/ckPic.mjs'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
setTimeout(async() => {
|
|
9
|
+
let r
|
|
10
|
+
|
|
11
|
+
// //mouseClick
|
|
12
|
+
// await mk.mouseClick(215, 905)
|
|
13
|
+
// await mk.mouseClick(100, 100)
|
|
14
|
+
// await mk.mouseClick(676, 908)
|
|
15
|
+
|
|
16
|
+
// //sendString
|
|
17
|
+
// await mk.sendString('Hello World!')
|
|
18
|
+
// await mk.sendString('abc中文')
|
|
19
|
+
|
|
20
|
+
// //screenSave
|
|
21
|
+
// await sc.screenSave(0,0,600,1000,'./ztest.png')
|
|
22
|
+
|
|
23
|
+
// //calcSimilarity
|
|
24
|
+
// r = await cp.calcSimilarity('./screen/首頁.png', './zscreen.png', 1)
|
|
25
|
+
// console.log('calcSimilarity',r)
|
|
26
|
+
|
|
27
|
+
// //calcSimilarityAndDraw
|
|
28
|
+
// r = await cp.calcSimilarityAndDraw('./screen/掉落.png', './zscreen.png', 1, './ztest.png')
|
|
29
|
+
// console.log('calcSimilarityAndDraw', r)
|
|
30
|
+
|
|
31
|
+
r = await ckPic('view', { threshold: 0.95 })
|
|
32
|
+
console.log('ckPic', r)
|
|
33
|
+
|
|
34
|
+
// let loc = {
|
|
35
|
+
// 'x': 480,
|
|
36
|
+
// 'y': 0,
|
|
37
|
+
// 'width': 480,
|
|
38
|
+
// 'height': 1080,
|
|
39
|
+
// }
|
|
40
|
+
// r = await ckPic('view', { ...loc, threshold: 0.95 })
|
|
41
|
+
// console.log('ckPic(loc)', r)
|
|
42
|
+
|
|
43
|
+
}, 2000) //2s內須開啟指定畫面供偵測測試
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
//node g.mjs
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import cv from '@u4/opencv4nodejs'
|
|
2
|
+
|
|
3
|
+
//1.下載OpenCV,下載網址:
|
|
4
|
+
// https://github.com/opencv/opencv/releases選opencv-4.12.0-windows.exe
|
|
5
|
+
// windows.exe為免安裝版,下載後解壓縮至C:\tools
|
|
6
|
+
// 注意須確保路徑有效:
|
|
7
|
+
// C:\tools\opencv\build\include
|
|
8
|
+
// C:\tools\opencv\build\x64\vc16\bin
|
|
9
|
+
// C:\tools\opencv\build\x64\vc16\lib
|
|
10
|
+
|
|
11
|
+
//2.於package.json內新增opencv4nodejs所需opencv路徑
|
|
12
|
+
// "opencv4nodejs": {
|
|
13
|
+
// "disableAutoBuild": "1",
|
|
14
|
+
// "opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
|
|
15
|
+
// "opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc16\\lib",
|
|
16
|
+
// "opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc16\\bin"
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
//3.於終端機(PowerShell)視窗內輸入設定參數
|
|
20
|
+
// $Env:OPENCV4NODEJS_DISABLE_AUTOBUILD = "1"
|
|
21
|
+
// $Env:OPENCV_INCLUDE_DIR = "C:\tools\opencv\build\include"
|
|
22
|
+
// $Env:OPENCV_LIB_DIR = "C:\tools\opencv\build\x64\vc16\lib"
|
|
23
|
+
// $Env:OPENCV_BIN_DIR = "C:\tools\opencv\build\x64\vc16\bin"
|
|
24
|
+
// $Env:Path = "$Env:OPENCV_BIN_DIR;$Env:Path"
|
|
25
|
+
|
|
26
|
+
//4.輸出變數確認
|
|
27
|
+
// echo $Env:OPENCV_INCLUDE_DIR
|
|
28
|
+
// echo $Env:OPENCV_LIB_DIR
|
|
29
|
+
// echo $Env:OPENCV_BIN_DIR
|
|
30
|
+
|
|
31
|
+
//5.執行npm i @u4/opencv4nodejs,若msvs有多版本則須指定npm i @u4/opencv4nodejs --msvs_version=2022
|
|
32
|
+
|
|
33
|
+
console.log(cv.version)
|
|
34
|
+
// => { major: 4, minor: 7, revision: 0 }
|
|
35
|
+
|
|
36
|
+
//node g.test_opencv.mjs
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "w-mousekey",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/w-mousekey.umd.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@u4/opencv4nodejs": "^7.1.2",
|
|
7
|
+
"json5": "^2.2.3",
|
|
8
|
+
"screenshot-desktop": "^1.15.1",
|
|
9
|
+
"sharp": "^0.34.3",
|
|
10
|
+
"wsemi": "^1.8.16"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"w-package-tools": "^1.1.2"
|
|
14
|
+
},
|
|
15
|
+
"opencv4nodejs": {
|
|
16
|
+
"disableAutoBuild": "1",
|
|
17
|
+
"opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
|
|
18
|
+
"opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc16\\lib",
|
|
19
|
+
"opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc16\\bin"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "mocha --parallel --timeout 60000",
|
|
23
|
+
"deploy": "gh-pages -d docs"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/yuda-lyu/w-mousekey.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"package",
|
|
31
|
+
"tool",
|
|
32
|
+
"opencv",
|
|
33
|
+
"opencv4nodejs",
|
|
34
|
+
"detect",
|
|
35
|
+
"mouse",
|
|
36
|
+
"keyboard",
|
|
37
|
+
"node"
|
|
38
|
+
],
|
|
39
|
+
"author": "yuda-lyu(semisphere)",
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|
package/pic/view.png
ADDED
|
Binary file
|
package/script.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#node toolg/addVersion.mjs
|
|
2
|
+
node toolg/modifyReadme.mjs
|
|
3
|
+
|
|
4
|
+
node toolg/cleanFolder.mjs
|
|
5
|
+
./node_modules/.bin/jsdoc -c .jsdoc
|
|
6
|
+
|
|
7
|
+
node toolg/gDistRollup.mjs
|
|
8
|
+
|
|
9
|
+
git add . -A
|
|
10
|
+
git commit -m 'modify: '
|
|
11
|
+
git push origin master:master
|
|
12
|
+
|
|
13
|
+
npm run deploy
|
|
14
|
+
|
|
15
|
+
#npm test
|
|
16
|
+
|
|
17
|
+
#npm publish
|
package/src/action.mjs
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import _ from 'lodash-es'
|
|
3
|
+
import w from 'wsemi'
|
|
4
|
+
import mk from './mousekey.mjs'
|
|
5
|
+
import sc from './screen.mjs'
|
|
6
|
+
import cp from './compare.mjs'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let action = (rtx, rty, rtw, rth, fpScreen) => {
|
|
10
|
+
|
|
11
|
+
// let screenSave = async() => {
|
|
12
|
+
// await sc.screenSave(rtx, rty, rtw, rth, fpScreen)
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
// let getCenter = (r) => {
|
|
16
|
+
// let cx = r.x + r.width / 2
|
|
17
|
+
// let cy = r.y + r.height / 2
|
|
18
|
+
// return {
|
|
19
|
+
// cx,
|
|
20
|
+
// cy,
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
// let findTarget = async(name, opt = {}) => {
|
|
25
|
+
|
|
26
|
+
// //scale
|
|
27
|
+
// let scale = _.get(opt, 'scale', 1)
|
|
28
|
+
// // console.log('scale',scale)
|
|
29
|
+
|
|
30
|
+
// //useToGray
|
|
31
|
+
// let useToGray = _.get(opt, 'useToGray', null)
|
|
32
|
+
// // console.log('useToGray',useToGray)
|
|
33
|
+
|
|
34
|
+
// //fp
|
|
35
|
+
// let fp = _.get(opt, 'fp')
|
|
36
|
+
// // console.log('fp',fp)
|
|
37
|
+
|
|
38
|
+
// //r
|
|
39
|
+
// if (w.isestr(fp)) {
|
|
40
|
+
|
|
41
|
+
// //calcSimilarityAndDraw
|
|
42
|
+
// r = await cp.calcSimilarityAndDraw(`./screen/${name}.png`, fpScreen, scale, fp, { useToGray })
|
|
43
|
+
// // console.log('calcSimilarityAndDraw',r)
|
|
44
|
+
|
|
45
|
+
// }
|
|
46
|
+
// else {
|
|
47
|
+
|
|
48
|
+
// //calcSimilarity
|
|
49
|
+
// r = await cp.calcSimilarity(`./screen/${name}.png`, fpScreen, scale, { useToGray })
|
|
50
|
+
// // console.log('calcSimilarity',r)
|
|
51
|
+
|
|
52
|
+
// }
|
|
53
|
+
|
|
54
|
+
// //getCenter
|
|
55
|
+
// let c = getCenter(r)
|
|
56
|
+
// // console.log('c',c)
|
|
57
|
+
|
|
58
|
+
// return {
|
|
59
|
+
// ...r,
|
|
60
|
+
// ...c,
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// let findTargetAndClick = async(name, opt = {}) => {
|
|
65
|
+
|
|
66
|
+
// //scale
|
|
67
|
+
// let scale = _.get(opt, 'scale', 1)
|
|
68
|
+
// // console.log('scale',scale)
|
|
69
|
+
|
|
70
|
+
// //useToGray
|
|
71
|
+
// let useToGray = _.get(opt, 'useToGray', null)
|
|
72
|
+
// // console.log('useToGray',useToGray)
|
|
73
|
+
|
|
74
|
+
// //fpFind
|
|
75
|
+
// let fpFind = _.get(opt, 'fpFind')
|
|
76
|
+
// // console.log('fpFind',fpFind)
|
|
77
|
+
|
|
78
|
+
// //fpClick
|
|
79
|
+
// let fpClick = _.get(opt, 'fpClick')
|
|
80
|
+
// // console.log('fpClick',fpClick)
|
|
81
|
+
|
|
82
|
+
// //sx, sy
|
|
83
|
+
// let sx = _.get(opt, 'sx', 0)
|
|
84
|
+
// let sy = _.get(opt, 'sy', 0)
|
|
85
|
+
// // console.log('sx',sx)
|
|
86
|
+
// // console.log('sy',sy)
|
|
87
|
+
|
|
88
|
+
// //threshold
|
|
89
|
+
// let threshold = _.get(opt, 'threshold', 0.9)
|
|
90
|
+
// if (!w.isnum(threshold)) {
|
|
91
|
+
// threshold = 0.9
|
|
92
|
+
// }
|
|
93
|
+
// threshold = w.cdbl(threshold)
|
|
94
|
+
|
|
95
|
+
// //findTarget
|
|
96
|
+
// let r = await findTarget(name, { scale, useToGray, fp: fpFind })
|
|
97
|
+
// // console.log('findTarget',r)
|
|
98
|
+
|
|
99
|
+
// //check
|
|
100
|
+
// if (r.similarity < threshold) {
|
|
101
|
+
// console.log('r', r)
|
|
102
|
+
// throw new Error(`can not find name[${name}] for click`)
|
|
103
|
+
// // return Promise.reject(`can not find name[${name}] for click`)
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
// await w.delay(1500)
|
|
107
|
+
|
|
108
|
+
// let px = r.cx + sx
|
|
109
|
+
// let py = r.cy + sy
|
|
110
|
+
|
|
111
|
+
// //點擊前預先繪製與存圖
|
|
112
|
+
// if (w.isestr(fpClick)) {
|
|
113
|
+
// await cp.screenAndDrawCircle(rtx, rty, rtw, rth, px, py, fpClick)
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// //mouseClick
|
|
117
|
+
// await mk.mouseClick(px, py)
|
|
118
|
+
// // console.log('mouseClick',px, py)
|
|
119
|
+
|
|
120
|
+
// return r
|
|
121
|
+
// }
|
|
122
|
+
|
|
123
|
+
// let r = {
|
|
124
|
+
// screenSave,
|
|
125
|
+
// getCenter,
|
|
126
|
+
// findTarget,
|
|
127
|
+
// findTargetAndClick,
|
|
128
|
+
// }
|
|
129
|
+
// return r
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default action
|
package/src/ckPic.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import get from 'lodash-es/get.js'
|
|
2
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
3
|
+
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
4
|
+
import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
|
|
5
|
+
import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
|
|
6
|
+
import mk from './mousekey.mjs'
|
|
7
|
+
import sc from './screen.mjs'
|
|
8
|
+
import cp from './compare.mjs'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let getCenter = (r) => {
|
|
12
|
+
let cx = r.x + r.width / 2
|
|
13
|
+
let cy = r.y + r.height / 2
|
|
14
|
+
return {
|
|
15
|
+
cx,
|
|
16
|
+
cy,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let ckPic = async(name, opt = {}) => {
|
|
21
|
+
let b = false
|
|
22
|
+
|
|
23
|
+
//fdTar
|
|
24
|
+
let fdTar = get(opt, 'fdTar', null)
|
|
25
|
+
if (!isestr(fdTar)) {
|
|
26
|
+
fdTar = './pic'
|
|
27
|
+
}
|
|
28
|
+
if (!fsIsFolder(fdTar)) {
|
|
29
|
+
throw new Error(`opt.fdTar[${opt.fdTar}] is not a folder`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//fdTmp
|
|
33
|
+
let fdTmp = get(opt, 'fdTmp', null)
|
|
34
|
+
if (!isestr(fdTmp)) {
|
|
35
|
+
fdTmp = './_tmp'
|
|
36
|
+
}
|
|
37
|
+
if (!fsIsFolder(fdTmp)) {
|
|
38
|
+
fsCreateFolder(fdTmp)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//fpTar
|
|
42
|
+
let fpTar = `${fdTar}/${name}.png`
|
|
43
|
+
if (!fsIsFile(fpTar)) {
|
|
44
|
+
throw new Error(`fpTar[${fpTar}] is not a file`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//fpAll, fpDet
|
|
48
|
+
let fpAll = `${fdTmp}/${name}.all.png`
|
|
49
|
+
let fpDet = `${fdTmp}/${name}.det.png`
|
|
50
|
+
|
|
51
|
+
let x = get(opt, 'x', 0)
|
|
52
|
+
let y = get(opt, 'y', 0)
|
|
53
|
+
let width = get(opt, 'width', 1920)
|
|
54
|
+
let height = get(opt, 'height', 1080)
|
|
55
|
+
|
|
56
|
+
let threshold = get(opt, 'threshold', 0.9)
|
|
57
|
+
let dx = get(opt, 'dx', 0)
|
|
58
|
+
let dy = get(opt, 'dy', 0)
|
|
59
|
+
|
|
60
|
+
let noClick = get(opt, 'noClick', false)
|
|
61
|
+
|
|
62
|
+
//screenSave
|
|
63
|
+
await sc.screenSave(x, y, width, height, fpAll)
|
|
64
|
+
|
|
65
|
+
//calcSimilarityAndDraw
|
|
66
|
+
let r = await cp.calcSimilarityAndDraw(fpTar, fpAll, 1, fpDet)
|
|
67
|
+
// console.log('calcSimilarityAndDraw',r)
|
|
68
|
+
console.log(name, 'similarity', r.similarity)
|
|
69
|
+
|
|
70
|
+
//getCenter
|
|
71
|
+
let rr = getCenter(r)
|
|
72
|
+
|
|
73
|
+
//merge
|
|
74
|
+
r = {
|
|
75
|
+
...r,
|
|
76
|
+
...rr
|
|
77
|
+
}
|
|
78
|
+
// console.log('merge',r)
|
|
79
|
+
|
|
80
|
+
if (r.similarity > threshold) {
|
|
81
|
+
|
|
82
|
+
//mouseClick
|
|
83
|
+
if (!noClick) {
|
|
84
|
+
await mk.mouseClick(r.cx + x + dx, r.cy + y + dy)
|
|
85
|
+
// console.log('mouseClick',r.cx, r.cy)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
b = true
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return b
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
export default ckPic
|
package/src/compare.mjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import cv from '@u4/opencv4nodejs'
|
|
3
|
+
import get from 'lodash-es/get.js'
|
|
4
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
5
|
+
import ispint from 'wsemi/src/ispint.mjs'
|
|
6
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
7
|
+
import oc from 'wsemi/src/color.mjs'
|
|
8
|
+
import sc from './screen.mjs'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async function readImage(fp) {
|
|
12
|
+
|
|
13
|
+
//readFileSync, 使用readFileSync可支援中文路徑與中文檔名
|
|
14
|
+
let buffer = fs.readFileSync(fp)
|
|
15
|
+
|
|
16
|
+
return cv.imdecode(buffer)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function writeImage(fp, img) {
|
|
20
|
+
|
|
21
|
+
//imencode, 轉成png格式
|
|
22
|
+
let buffer = cv.imencode('.png', img) // 可用 .jpg, .bmp, .webp
|
|
23
|
+
|
|
24
|
+
//writeFileSync, 使用writeFileSync可支援中文路徑與中文檔名
|
|
25
|
+
fs.writeFileSync(fp, buffer)
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function calcSimilarityCore(imgTar, imgScreen, scale, opt = {}) {
|
|
30
|
+
|
|
31
|
+
//useToGray
|
|
32
|
+
let useToGray = get(opt, 'useToGray')
|
|
33
|
+
if (!isbol(useToGray)) {
|
|
34
|
+
useToGray = false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//resize
|
|
38
|
+
let imgTarResize = imgTar.resize(
|
|
39
|
+
Math.floor(imgTar.rows * scale),
|
|
40
|
+
Math.floor(imgTar.cols * scale)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
//check
|
|
44
|
+
if (imgTarResize.rows < 10 || imgTarResize.cols < 10) {
|
|
45
|
+
throw new Error(`縮放後檢測尺寸過小: [imgTarResize:${imgTarResize.cols}x${imgTarResize.rows}]`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//check
|
|
49
|
+
if (imgTarResize.rows > imgScreen.rows || imgTarResize.cols > imgScreen.cols) {
|
|
50
|
+
throw new Error(`縮放後檢測>截圖尺寸: [imgScreen:${imgScreen.cols}x${imgScreen.rows}] > [imgTarResize:${imgTarResize.cols}x${imgTarResize.rows}]`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//useToGray
|
|
54
|
+
if (useToGray) {
|
|
55
|
+
imgScreen = imgScreen.bgrToGray()
|
|
56
|
+
imgTarResize = imgTarResize.bgrToGray()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//matchTemplate
|
|
60
|
+
let result = imgScreen.matchTemplate(imgTarResize, cv.TM_CCOEFF_NORMED)
|
|
61
|
+
|
|
62
|
+
//minMaxLoc
|
|
63
|
+
let { maxVal, maxLoc } = result.minMaxLoc()
|
|
64
|
+
|
|
65
|
+
//params
|
|
66
|
+
let similarity = maxVal
|
|
67
|
+
let x = maxLoc.x
|
|
68
|
+
let y = maxLoc.y
|
|
69
|
+
let width = imgTarResize.cols
|
|
70
|
+
let height = imgTarResize.rows
|
|
71
|
+
|
|
72
|
+
//r
|
|
73
|
+
let r = {
|
|
74
|
+
similarity,
|
|
75
|
+
x,
|
|
76
|
+
y,
|
|
77
|
+
width,
|
|
78
|
+
height,
|
|
79
|
+
scale,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return r
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function calcSimilarity(fpTar, fpScreen, scale, opt = {}) {
|
|
86
|
+
|
|
87
|
+
//readImage
|
|
88
|
+
let imgScreen = await readImage(fpScreen)
|
|
89
|
+
let imgTar = await readImage(fpTar)
|
|
90
|
+
|
|
91
|
+
//calcSimilarityCore
|
|
92
|
+
let match = await calcSimilarityCore(imgTar, imgScreen, scale, opt)
|
|
93
|
+
|
|
94
|
+
return match
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function calcSimilarityAndDraw(fpTar, fpScreen, scale, fp, opt = {}) {
|
|
98
|
+
|
|
99
|
+
//drawBorderWidth
|
|
100
|
+
let drawBorderWidth = get(opt, 'drawBorderWidth')
|
|
101
|
+
if (!ispint(drawBorderWidth)) {
|
|
102
|
+
drawBorderWidth = 2
|
|
103
|
+
}
|
|
104
|
+
// console.log('drawBorderWidth',drawBorderWidth)
|
|
105
|
+
|
|
106
|
+
//drawBorderColor
|
|
107
|
+
let drawBorderColor = get(opt, 'drawBorderColor')
|
|
108
|
+
if (!isestr(drawBorderColor)) {
|
|
109
|
+
drawBorderColor = '#f00'
|
|
110
|
+
}
|
|
111
|
+
drawBorderColor = oc.toRgb(drawBorderColor)
|
|
112
|
+
// console.log('drawBorderColor',drawBorderColor)
|
|
113
|
+
|
|
114
|
+
//readImage
|
|
115
|
+
let imgScreen = await readImage(fpScreen)
|
|
116
|
+
let imgTar = await readImage(fpTar)
|
|
117
|
+
|
|
118
|
+
//calcSimilarityCore
|
|
119
|
+
let m = await calcSimilarityCore(imgTar, imgScreen, scale, opt)
|
|
120
|
+
// console.log('m',m)
|
|
121
|
+
|
|
122
|
+
//topLeft, bottomRight
|
|
123
|
+
let topLeft = new cv.Point2(m.x, m.y)
|
|
124
|
+
let bottomRight = new cv.Point2(m.x + m.width, m.y + m.height)
|
|
125
|
+
// console.log('topLeft',topLeft)
|
|
126
|
+
// console.log('bottomRight',bottomRight)
|
|
127
|
+
|
|
128
|
+
//drawRectangle
|
|
129
|
+
imgScreen.drawRectangle(
|
|
130
|
+
topLeft,
|
|
131
|
+
bottomRight,
|
|
132
|
+
new cv.Vec3(drawBorderColor.b, drawBorderColor.g, drawBorderColor.r),
|
|
133
|
+
drawBorderWidth,
|
|
134
|
+
cv.LINE_8 //8-connected線, 效果銳利清楚
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
//writeImage
|
|
138
|
+
await writeImage(fp, imgScreen)
|
|
139
|
+
|
|
140
|
+
//r
|
|
141
|
+
let r = {
|
|
142
|
+
...m,
|
|
143
|
+
fp,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return r
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function screenAndDrawCircle(x, y, width, height, px, py, fp, opt = {}) {
|
|
150
|
+
|
|
151
|
+
//drawCircleRadius
|
|
152
|
+
let drawCircleRadius = get(opt, 'drawCircleRadius')
|
|
153
|
+
if (!ispint(drawCircleRadius)) {
|
|
154
|
+
drawCircleRadius = 5
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//drawBorderWidth
|
|
158
|
+
let drawBorderWidth = get(opt, 'drawBorderWidth')
|
|
159
|
+
if (!ispint(drawBorderWidth)) {
|
|
160
|
+
drawBorderWidth = 2
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//drawBorderColor
|
|
164
|
+
let drawBorderColor = get(opt, 'drawBorderColor')
|
|
165
|
+
if (!isestr(drawBorderColor)) {
|
|
166
|
+
drawBorderColor = '#f00'
|
|
167
|
+
}
|
|
168
|
+
drawBorderColor = oc.toRgb(drawBorderColor)
|
|
169
|
+
// console.log('drawBorderColor',drawBorderColor)
|
|
170
|
+
|
|
171
|
+
//screenSave
|
|
172
|
+
await sc.screenSave(x, y, width, height, fp)
|
|
173
|
+
|
|
174
|
+
//readImage
|
|
175
|
+
let imgScreen = await readImage(fp)
|
|
176
|
+
|
|
177
|
+
//center
|
|
178
|
+
let center = new cv.Point2(px, py)
|
|
179
|
+
|
|
180
|
+
//drawCircle
|
|
181
|
+
imgScreen.drawCircle(
|
|
182
|
+
center,
|
|
183
|
+
drawCircleRadius,
|
|
184
|
+
new cv.Vec3(drawBorderColor.b, drawBorderColor.g, drawBorderColor.r),
|
|
185
|
+
drawBorderWidth,
|
|
186
|
+
cv.LINE_8 //8-connected線, 效果銳利清楚
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
//writeImage
|
|
190
|
+
await writeImage(fp, imgScreen)
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let obj = {
|
|
195
|
+
calcSimilarity,
|
|
196
|
+
calcSimilarityAndDraw,
|
|
197
|
+
screenAndDrawCircle,
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
export default obj
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import JSON5 from 'json5'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
let getSettings = () => {
|
|
6
|
+
let fp = './setting.json'
|
|
7
|
+
let s = {}
|
|
8
|
+
try {
|
|
9
|
+
let j = fs.readFileSync(fp, 'utf8')
|
|
10
|
+
s = JSON5.parse(j)
|
|
11
|
+
}
|
|
12
|
+
catch (err) {}
|
|
13
|
+
return s
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export default getSettings
|