danrim

AHK find text

Aug 3rd, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.57 KB | None | 0 0
  1. ;/*
  2. ;===========================================
  3. ; FindText - Capture screen image into text and then find it
  4. ; https://autohotkey.com/boards/viewtopic.php?f=6&t=17834
  5. ;
  6. ; Author : FeiYue
  7. ; Version : 6.7
  8. ; Date : 2019-04-13
  9. ;
  10. ; Usage:
  11. ; 1. Capture the image to text string.
  12. ; 2. Test find the text string on full Screen.
  13. ; 3. When test is successful, you may copy the code
  14. ; and paste it into your own script.
  15. ; Note: Copy the "FindText()" function and the following
  16. ; functions and paste it into your own script Just once.
  17. ;
  18. ; Note:
  19. ; After upgrading to v6.0, the search scope using WinAPI's
  20. ; upper left corner X, Y coordinates, and width, height.
  21. ; This will be better understood and used.
  22. ;
  23. ;===========================================
  24. ; Introduction of function parameters:
  25. ;
  26. ; returnArray := FindText(
  27. ; X --> the search scope's upper left corner X coordinates
  28. ; , Y --> the search scope's upper left corner Y coordinates
  29. ; , W --> the search scope's Width
  30. ; , H --> the search scope's Height
  31. ; , Character "0" fault-tolerant in percentage --> 0.1=10%
  32. ; , Character "_" fault-tolerant in percentage --> 0.1=10%
  33. ; , Text --> can be a lot of text parsed into images, separated by "|"
  34. ; , ScreenShot --> if the value is 0, the last screenshot will be used
  35. ; , FindAll --> if the value is 0, Just find one result and return
  36. ; , JoinText --> if the value is 1, Join all Text for combination lookup
  37. ; , offsetX --> Set the max text offset for combination lookup
  38. ; , offsetY --> Set the max text offset for combination lookup
  39. ; )
  40. ;
  41. ; The range used by AHK is determined by the upper left
  42. ; corner and the lower right corner: (x1, y1, x2, y2),
  43. ; it can be converted to: FindText(x1, y1, x2-x1+1, y2-y1+1, ...).
  44. ;
  45. ; return a second-order array contains the [X,Y,W,H,Comment] of Each Find,
  46. ; if no image is found, the function returns 0.
  47. ;
  48. ;===========================================
  49. ;*/
  50.  
  51. if (A_IsCompiled or A_LineFile!=A_ScriptFullPath)
  52. Goto, ft_End
  53.  
  54. ft_Start:
  55.  
  56. IfNotEqual, ft_ToolTip_Text,, Goto, ft_Main_Window
  57. #NoEnv
  58. #SingleInstance force
  59. SetBatchLines, -1
  60. Menu, Tray, Add
  61. Menu, Tray, Add, FinText, ft_Main_Window
  62. if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
  63. {
  64. Menu, Tray, Default, FinText
  65. Menu, Tray, Click, 1
  66. Menu, Tray, Icon, Shell32.dll, 23
  67. }
  68. ; The capture range can be changed by adjusting the numbers
  69. ;----------------------------
  70. ft_ww:=35, ft_hh:=12
  71. ;----------------------------
  72. ft_nW:=2*ft_ww+1, ft_nH:=2*ft_hh+1
  73. Gosub, ft_MakeCaptureWindow
  74. Gosub, ft_MakeMainWindow
  75. Gosub, ft_Load_ToolTip_Text
  76. return
  77.  
  78. ft_Load_ToolTip_Text:
  79. ft_ToolTip_Text=
  80. (LTrim
  81. Capture = Initiate Image Capture Sequence
  82. Test = Test Results of Code
  83. Copy = Copy Code to Clipboard
  84. AddFunc = Additional FindText() in Copy
  85. U = Cut the Upper Edge by 1
  86. U3 = Cut the Upper Edge by 3
  87. L = Cut the Left Edge by 1
  88. L3 = Cut the Left Edge by 3
  89. R = Cut the Right Edge by 1
  90. R3 = Cut the Right Edge by 3
  91. D = Cut the Lower Edge by 1
  92. D3 = Cut the Lower Edge by 3
  93. SelR = Red component of the selected color
  94. SelG = Green component of the selected color
  95. SelB = Blue component of the selected color
  96. DiffR = Red Difference which Determines Black or White Pixel Conversion (0-255)
  97. DiffG = Green Difference which Determines Black or White Pixel Conversion (0-255)
  98. DiffB = Blue Difference which Determines Black or White Pixel Conversion (0-255)
  99. Auto = Automatic Cutting Edge
  100. Similar = Adjust color similarity as Equivalent to The Selected Color
  101. Similar2 = Adjust color similarity as Equivalent to The Selected Color
  102. SelColor = The selected color
  103. SelGray = Gray value of the selected color
  104. Threshold = Gray Threshold which Determines Black or White Pixel Conversion (0-255)
  105. GrayDiff = Gray Difference which Determines Black or White Pixel Conversion (0-255)
  106. UsePos = Use position instead of color value to suit any color
  107. Modify = Allows Modify the Black and White Image
  108. Reset = Reset to Original Captured Image
  109. Comment = Optional Comment used to Label Code ( Within <> )
  110. SplitAdd = Using Markup Segmentation to Generate Text Library
  111. AllAdd = Append Another FindText Search Text into Previously Generated Code
  112. OK = Create New FindText Code for Testing
  113. Close = Close the Window Don't Do Anything
  114. Gray2Two = Converts Image Pixels from Grays to Black or White
  115. GrayDiff2Two = Converts Image Pixels from Gray Difference to Black or White
  116. Color2Two = Converts Image Pixels from Color to Black or White
  117. ColorPos2Two = Converts Image Pixels from Color Position to Black or White
  118. ColorDiff2Two = Converts Image Pixels from Color Difference to Black or White
  119. )
  120. return
  121.  
  122. ft_Main_Window:
  123. Gui, ft_Main:Show, Center
  124. return
  125.  
  126. ft_MakeMainWindow:
  127. Gui, ft_Main:Default
  128. Gui, +AlwaysOnTop
  129. Gui, Margin, 15, 15
  130. Gui, Color, DDEEFF
  131. Gui, Font, s6 bold, Verdana
  132. Gui, Add, Edit, xm w660 r25 vft_MyPic -Wrap -VScroll
  133. Gui, Font, s12 norm, Verdana
  134. Gui, Add, Button, w220 gft_MainRun, Capture
  135. Gui, Add, Button, x+0 wp gft_MainRun, Test
  136. Gui, Add, Button, x+0 wp gft_MainRun Section, Copy
  137. Gui, Font, s10
  138. Gui, Add, Text, xm, Click Text String to See ASCII Search Text in the Above
  139. Gui, Add, Checkbox, xs yp w220 r1 -Wrap Checked vft_AddFunc, Additional FindText() in Copy
  140. Gui, Font, s12 cBlue, Verdana
  141. Gui, Add, Edit, xm w660 h350 vft_scr Hwndft_hscr -Wrap HScroll
  142. Gui, Show,, Capture Image To Text And Find Text Tool
  143. ;---------------------------------------
  144. OnMessage(0x100, Func("ft_EditEvents1")) ; WM_KEYDOWN
  145. OnMessage(0x201, Func("ft_EditEvents2")) ; WM_LBUTTONDOWN
  146. OnMessage(0x200, Func("ft_ShowToolTip")) ; WM_MOUSEMOVE
  147. return
  148.  
  149. ft_EditEvents1()
  150. {
  151. ListLines, Off
  152. if (A_Gui="ft_Main" && A_GuiControl="ft_scr")
  153. SetTimer, ft_ShowPic, -100
  154. }
  155.  
  156. ft_EditEvents2()
  157. {
  158. ListLines, Off
  159. if (A_Gui="ft_Capture")
  160. ft_WM_LBUTTONDOWN()
  161. else
  162. ft_EditEvents1()
  163. }
  164.  
  165. ft_ShowPic:
  166. ListLines, Off
  167. Critical
  168. ControlGet, i, CurrentLine,,, ahk_id %ft_hscr%
  169. ControlGet, s, Line, %i%,, ahk_id %ft_hscr%
  170. GuiControl, ft_Main:, ft_MyPic, % Trim(ASCII(s),"`n")
  171. return
  172.  
  173. ft_ShowToolTip()
  174. {
  175. ListLines, Off
  176. global ft_ToolTip_Text
  177. static CurrControl, PrevControl, _TT
  178. CurrControl := A_GuiControl
  179. if (CurrControl != PrevControl)
  180. {
  181. PrevControl := CurrControl
  182. ToolTip
  183. if (CurrControl != "")
  184. SetTimer, ft_DisplayToolTip, -500
  185. }
  186. return
  187.  
  188. ft_DisplayToolTip:
  189. ListLines, Off
  190. MouseGetPos,,, _TT
  191. WinGetClass, _TT, ahk_id %_TT%
  192. if (_TT = "AutoHotkeyGUI")
  193. {
  194. ToolTip, % RegExMatch(ft_ToolTip_Text, "m`n)^"
  195. . StrReplace(CurrControl,"ft_") . "\K\s*=.*", _TT)
  196. ? StrReplace(Trim(_TT,"`t ="),"\n","`n") : ""
  197. SetTimer, ft_RemoveToolTip, -5000
  198. }
  199. return
  200.  
  201. ft_RemoveToolTip:
  202. ToolTip
  203. return
  204. }
  205.  
  206. ft_MainRun:
  207. k:="ft_" . A_GuiControl
  208. WinMinimize
  209. Gui, Hide
  210. DetectHiddenWindows, Off
  211. Gui, +LastFound
  212. WinWaitClose, % "ahk_id " WinExist()
  213. if IsLabel(k)
  214. Gosub, %k%
  215. Gui, ft_Main: Show
  216. GuiControl, ft_Main: Focus, ft_scr
  217. return
  218.  
  219. ft_Copy:
  220. GuiControlGet, s,, ft_scr
  221. GuiControlGet, r,, ft_AddFunc
  222. if (r != 1)
  223. s:=RegExReplace(s,"\n\K[\s;=]+ Copy The[\s\S]*")
  224. Clipboard:=StrReplace(s,"`n","`r`n")
  225. s=
  226. return
  227.  
  228. ft_Capture:
  229. Gui, ft_Mini:Default
  230. Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x08000000
  231. Gui, Color, Red
  232. d:=2, w:=ft_nW+2*d, h:=ft_nH+2*d, i:=w-d, j:=h-d
  233. Gui, Show, Hide w%w% h%h%
  234. s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
  235. s=%s% %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
  236. WinSet, Region, %s%
  237. ;------------------------------
  238. Hotkey, $*RButton, ft_RButton_Off, On
  239. ListLines, Off
  240. CoordMode, Mouse
  241. ft_oldx:=ft_oldy:=""
  242. Loop {
  243. Sleep, 50
  244. MouseGetPos, x, y
  245. if (ft_oldx=x and ft_oldy=y)
  246. Continue
  247. ft_oldx:=x, ft_oldy:=y
  248. ;---------------
  249. Gui, Show, % "NA x" (x-w//2) " y" (y-h//2)
  250. ToolTip, % "The Capture Position : " x "," y
  251. . "`nFirst click RButton to start capturing"
  252. . "`nSecond click RButton to end capture"
  253. } Until GetKeyState("RButton", "P")
  254. KeyWait, RButton
  255. ft_px:=x, ft_py:=y, ft_oldx:=ft_oldy:=""
  256. Loop {
  257. Sleep, 50
  258. MouseGetPos, x, y
  259. if (ft_oldx=x and ft_oldy=y)
  260. Continue
  261. ft_oldx:=x, ft_oldy:=y
  262. ;---------------
  263. ToolTip, % "The Capture Position : " ft_px "," ft_py
  264. . "`nFirst click RButton to start capturing"
  265. . "`nSecond click RButton to end capture"
  266. } Until GetKeyState("RButton", "P")
  267. KeyWait, RButton
  268. ToolTip
  269. ListLines, On
  270. Gui, Destroy
  271. WinWaitClose
  272. ft_cors:=ft_getc(ft_px,ft_py,ft_ww,ft_hh)
  273. Hotkey, $*RButton, ft_RButton_Off, Off
  274. Goto, ft_ShowCaptureWindow
  275. ft_RButton_Off:
  276. return
  277.  
  278. ft_ShowCaptureWindow:
  279. ft_cors.Event:="", ft_cors.Result:=""
  280. ;--------------------------------
  281. Gui, ft_Capture:Default
  282. k:=ft_nW*ft_nH+1
  283. Loop, % ft_nW
  284. GuiControl,, % ft_C_[k++], 0
  285. Loop, 6
  286. GuiControl,, Edit%A_Index%
  287. GuiControl,, ft_Modify, % ft_Modify:=0
  288. GuiControl,, ft_GrayDiff, 50
  289. GuiControl, Focus, ft_Threshold
  290. Gosub, ft_Reset
  291. Gui, Show, Center
  292. DetectHiddenWindows, Off
  293. Gui, +LastFound
  294. WinWaitClose, % "ahk_id " WinExist()
  295. ;--------------------------------
  296. if InStr(ft_cors.Event,"OK")
  297. {
  298. if !A_IsCompiled
  299. {
  300. FileRead, s, %A_LineFile%
  301. s:=SubStr(s, s~="i)\n[;=]+ Copy The")
  302. } else s:=""
  303. GuiControl, ft_Main:, ft_scr, % ft_cors.Result "`n" s
  304. ft_cors.Result:=s:=""
  305. return
  306. }
  307. if InStr(ft_cors.Event,"Add")
  308. ft_add(ft_cors.Result, 0), ft_cors.Result:=""
  309. return
  310.  
  311. ft_WM_LBUTTONDOWN()
  312. {
  313. global
  314. ListLines, Off
  315. Critical
  316. MouseGetPos,,,, j
  317. IfNotInString, j, progress
  318. return
  319. Gui, ft_Capture:Default
  320. MouseGetPos,,,, j, 2
  321. For k,v in ft_C_
  322. if (v=j)
  323. {
  324. if (k>ft_nW*ft_nH)
  325. {
  326. GuiControlGet, i,, %v%
  327. GuiControl,, %v%, % i ? 0:100
  328. }
  329. else if (ft_Modify and ft_bg!="")
  330. {
  331. c:=ft_ascii[k], ft_ascii[k]:=c="0" ? "_" : c="_" ? "0" : c
  332. c:=c="0" ? "White" : c="_" ? "Black" : ft_WindowColor
  333. Gosub, ft_SetColor
  334. }
  335. else
  336. {
  337. c:=ft_cors[k], ft_cors.SelPos:=k
  338. r:=(c>>16)&0xFF, g:=(c>>8)&0xFF, b:=c&0xFF
  339. GuiControl,, ft_SelGray, % (r*38+g*75+b*15)>>7
  340. GuiControl,, ft_SelColor, %c%
  341. GuiControl,, ft_SelR, %r%
  342. GuiControl,, ft_SelG, %g%
  343. GuiControl,, ft_SelB, %b%
  344. }
  345. return
  346. }
  347. }
  348.  
  349. ft_getc(px, py, ww, hh)
  350. {
  351. xywh2xywh(px-ww,py-hh,2*ww+1,2*hh+1,x,y,w,h)
  352. if (w<1 or h<1)
  353. return, 0
  354. bch:=A_BatchLines
  355. SetBatchLines, -1
  356. ;--------------------------------------
  357. GetBitsFromScreen(x,y,w,h,Scan0,Stride,1)
  358. ;--------------------------------------
  359. cors:=[], k:=0, nW:=2*ww+1, nH:=2*hh+1
  360. lls:=A_ListLines=0 ? "Off" : "On"
  361. ListLines, Off
  362. fmt:=A_FormatInteger
  363. SetFormat, IntegerFast, H
  364. Loop, %nH% {
  365. j:=py-hh+A_Index-1
  366. Loop, %nW% {
  367. i:=px-ww+A_Index-1, k++
  368. if (i>=x and i<=x+w-1 and j>=y and j<=y+h-1)
  369. c:=NumGet(Scan0+0,(j-y)*Stride+(i-x)*4,"uint")
  370. , cors[k]:="0x" . SubStr(0x1000000|c,-5)
  371. else
  372. cors[k]:="0xFFFFFF"
  373. }
  374. }
  375. SetFormat, IntegerFast, %fmt%
  376. ListLines, %lls%
  377. cors.LeftCut:=Abs(px-ww-x)
  378. cors.RightCut:=Abs(px+ww-(x+w-1))
  379. cors.UpCut:=Abs(py-hh-y)
  380. cors.DownCut:=Abs(py+hh-(y+h-1))
  381. SetBatchLines, %bch%
  382. return, cors
  383. }
  384.  
  385. ft_Test:
  386. GuiControlGet, s, ft_Main:, ft_scr
  387. s:="`n#NoEnv`nMenu, Tray, Click, 1`n"
  388. . "Gui, _ok_:Show, Hide, _ok_`n"
  389. . s "`nExitApp`n#SingleInstance off`n"
  390. if (!A_IsCompiled) and InStr(s,"MCode(")
  391. {
  392. ft_Exec(s)
  393. DetectHiddenWindows, On
  394. WinWait, _ok_ ahk_class AutoHotkeyGUI,, 3
  395. if !ErrorLevel
  396. WinWaitClose, _ok_ ahk_class AutoHotkeyGUI
  397. }
  398. else
  399. {
  400. CoordMode, Mouse
  401. t:=A_TickCount, RegExMatch(s,"\[\d+,\s*\d+\]",r)
  402. RegExMatch(s,"=""\K[^$\n]+\$\d+\.[\w+/]+",v)
  403. k:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, v)
  404. X:=k.1.1, Y:=k.1.2, W:=k.1.3, H:=k.1.4, X+=W//2, Y+=H//2
  405. MsgBox, 4096,, % "Time:`t" (A_TickCount-t) " ms`n`n"
  406. . "Pos:`t" r " " X ", " Y "`n`n"
  407. . "Result:`t" (k ? "Success !":"Failed !"), 3
  408. (k) and MouseTip(X, Y)
  409. k:=""
  410. }
  411. return
  412.  
  413. ft_Exec(s)
  414. {
  415. Ahk:=A_IsCompiled ? A_ScriptDir "\AutoHotkey.exe":A_AhkPath
  416. s:=RegExReplace(s, "\R", "`r`n")
  417. Try {
  418. shell:=ComObjCreate("WScript.Shell")
  419. oExec:=shell.Exec(Ahk " /f /ErrorStdOut *")
  420. oExec.StdIn.Write(s)
  421. oExec.StdIn.Close()
  422. }
  423. catch {
  424. f:=A_Temp "\~test1.tmp", s:="`r`n FileDelete, " f "`r`n" s
  425. FileDelete, %f%
  426. FileAppend, %s%, %f%
  427. Run, %Ahk% /f "%f%",, UseErrorLevel
  428. }
  429. }
  430.  
  431. ft_MakeCaptureWindow:
  432. ft_WindowColor:="0xCCDDEE"
  433. Gui, ft_Capture:Default
  434. Gui, +LastFound +AlwaysOnTop +ToolWindow
  435. Gui, Margin, 15, 15
  436. Gui, Color, %ft_WindowColor%
  437. Gui, Font, s14, Verdana
  438. Gui, -Theme
  439. w:=800//ft_nW, h:=(A_ScreenHeight-300)//ft_nH, w:=h<w ? h-1:w-1
  440. Loop, % ft_nW*(ft_nH+1) {
  441. i:=A_Index, j:=i=1 ? "" : Mod(i,ft_nW)=1 ? "xm y+1" : "x+1"
  442. j.=i>ft_nW*ft_nH ? " cRed BackgroundFFFFAA":""
  443. Gui, Add, Progress, w%w% h%w% %j%
  444. }
  445. WinGet, s, ControlListHwnd
  446. ft_C_:=StrSplit(s,"`n"), s:=""
  447. Loop, % ft_nW*(ft_nH+1)
  448. Control, ExStyle, -0x20000,, % "ahk_id " ft_C_[A_Index]
  449. Gui, +Theme
  450. Gui, Add, Button, xm+95 w45 gft_Run, U
  451. Gui, Add, Button, x+0 wp gft_Run, U3
  452. ;--------------
  453. Gui, Add, Text, x+42 yp+3 Section, Gray
  454. Gui, Add, Edit, x+3 yp-3 w60 vft_SelGray ReadOnly
  455. Gui, Add, Text, x+15 ys, Color
  456. Gui, Add, Edit, x+3 yp-3 w120 vft_SelColor ReadOnly
  457. Gui, Add, Text, x+15 ys, R
  458. Gui, Add, Edit, x+3 yp-3 w60 vft_SelR ReadOnly
  459. Gui, Add, Text, x+5 ys, G
  460. Gui, Add, Edit, x+3 yp-3 w60 vft_SelG ReadOnly
  461. Gui, Add, Text, x+5 ys, B
  462. Gui, Add, Edit, x+3 yp-3 w60 vft_SelB ReadOnly
  463. ;--------------
  464. Gui, Add, Button, xm w45 gft_Run, L
  465. Gui, Add, Button, x+0 wp gft_Run, L3
  466. Gui, Add, Button, x+15 w70 gft_Run, Auto
  467. Gui, Add, Button, x+15 w45 gft_Run, R
  468. Gui, Add, Button, x+0 wp gft_Run Section, R3
  469. Gui, Add, Button, xm+95 w45 gft_Run, D
  470. Gui, Add, Button, x+0 wp gft_Run, D3
  471. ;------------------
  472. Gui, Add, Tab3, ys-8 -Wrap, Gray|GrayDiff|Color|ColorPos|ColorDiff
  473. Gui, Tab, 1
  474. Gui, Add, Text, x+15 y+15, Gray Threshold
  475. Gui, Add, Edit, x+15 w100 vft_Threshold
  476. Gui, Add, Button, x+15 yp-3 gft_Run Default, Gray2Two
  477. Gui, Tab, 2
  478. Gui, Add, Text, x+15 y+15, Gray Difference
  479. Gui, Add, Edit, x+15 w100 vft_GrayDiff, 50
  480. Gui, Add, Button, x+15 yp-3 gft_Run, GrayDiff2Two
  481. Gui, Tab, 3
  482. Gui, Add, Text, x+15 y+15, Similarity 0
  483. Gui, Add, Slider
  484. , x+0 w100 vft_Similar gft_Run Page1 NoTicks ToolTip Center, 100
  485. Gui, Add, Text, x+0, 100
  486. Gui, Add, Button, x+15 yp-3 gft_Run, Color2Two
  487. Gui, Tab, 4
  488. Gui, Add, Text, x+15 y+15, Similarity 0
  489. Gui, Add, Slider
  490. , x+0 w100 vft_Similar2 gft_Run Page1 NoTicks ToolTip Center, 100
  491. Gui, Add, Text, x+0, 100
  492. Gui, Add, Button, x+15 yp-3 gft_Run, ColorPos2Two
  493. Gui, Tab, 5
  494. Gui, Add, Text, x+15 y+15, R
  495. Gui, Add, Edit, x+3 w70 vft_DiffR Limit3
  496. Gui, Add, UpDown, vft_dR Range0-255
  497. Gui, Add, Text, x+10, G
  498. Gui, Add, Edit, x+3 w70 vft_DiffG Limit3
  499. Gui, Add, UpDown, vft_dG Range0-255
  500. Gui, Add, Text, x+10, B
  501. Gui, Add, Edit, x+3 w70 vft_DiffB Limit3
  502. Gui, Add, UpDown, vft_dB Range0-255
  503. Gui, Add, Button, x+12 yp-3 gft_Run, ColorDiff2Two
  504. Gui, Tab
  505. ;------------------
  506. Gui, Add, Checkbox, xm gft_Run vft_Modify, Modify
  507. Gui, Add, Button, x+5 yp-3 gft_Run, Reset
  508. Gui, Add, Text, x+15 yp+3, Comment
  509. Gui, Add, Edit, x+5 w132 vft_Comment
  510. Gui, Add, Button, x+10 yp-3 gft_Run, SplitAdd
  511. Gui, Add, Button, x+10 gft_Run, AllAdd
  512. Gui, Add, Button, x+10 w80 gft_Run, OK
  513. Gui, Add, Button, x+10 gft_Run, Close
  514. Gui, Show, Hide, Capture Image To Text
  515. return
  516.  
  517. ft_Run:
  518. Critical
  519. k:=A_GuiControl
  520. k:= k="L" ? "LeftCut" : k="L3" ? "LeftCut3"
  521. : k="R" ? "RightCut" : k="R3" ? "RightCut3"
  522. : k="U" ? "UpCut" : k="U3" ? "UpCut3"
  523. : k="D" ? "DownCut" : k="D3" ? "DownCut3" : k
  524. Gui, +OwnDialogs
  525. k:=InStr(k,"ft_") ? k : "ft_" k
  526. if IsLabel(k)
  527. Gosub, %k%
  528. return
  529.  
  530. ft_Close:
  531. Gui, Cancel
  532. return
  533.  
  534. ft_Modify:
  535. GuiControlGet, ft_Modify
  536. return
  537.  
  538. ft_Similar:
  539. ft_Similar2:
  540. ListLines, Off
  541. GuiControl,, % InStr(A_ThisLabel,"2")
  542. ? "ft_Similar":"ft_Similar2", % %A_ThisLabel%
  543. return
  544.  
  545. ft_SetColor:
  546. c:=c="White" ? 0xFFFFFF : c="Black" ? 0x000000
  547. : ((c&0xFF)<<16)|(c&0xFF00)|((c&0xFF0000)>>16)
  548. SendMessage, 0x2001, 0, c,, % "ahk_id " . ft_C_[k]
  549. return
  550.  
  551. ft_Reset:
  552. if !IsObject(ft_ascii)
  553. ft_ascii:=[], ft_gs:=[]
  554. ft_left:=ft_right:=ft_up:=ft_down:=k:=0, ft_bg:=""
  555. Loop, % ft_nW*ft_nH {
  556. ft_ascii[++k]:=1, c:=ft_cors[k]
  557. ft_gs[k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
  558. Gosub, ft_SetColor
  559. }
  560. Loop, % ft_cors.LeftCut
  561. Gosub, ft_LeftCut
  562. Loop, % ft_cors.RightCut
  563. Gosub, ft_RightCut
  564. Loop, % ft_cors.UpCut
  565. Gosub, ft_UpCut
  566. Loop, % ft_cors.DownCut
  567. Gosub, ft_DownCut
  568. return
  569.  
  570. ft_Gray2Two:
  571. GuiControl, Focus, ft_Threshold
  572. GuiControlGet, ft_Threshold
  573. if (ft_Threshold="")
  574. {
  575. ft_pp:=[]
  576. Loop, 256
  577. ft_pp[A_Index-1]:=0
  578. Loop, % ft_nW*ft_nH
  579. if (ft_ascii[A_Index]!="")
  580. ft_pp[ft_gs[A_Index]]++
  581. ft_Threshold:=ft_GetThreshold(ft_pp)
  582. GuiControl,, ft_Threshold, %ft_Threshold%
  583. }
  584. ft_Threshold:=Round(ft_Threshold)
  585. ft_color:="*" ft_Threshold, k:=i:=0
  586. Loop, % ft_nW*ft_nH {
  587. if (ft_ascii[++k]="")
  588. Continue
  589. if (ft_gs[k]<=ft_Threshold)
  590. ft_ascii[k]:="0", c:="Black", i++
  591. else
  592. ft_ascii[k]:="_", c:="White", i--
  593. Gosub, ft_SetColor
  594. }
  595. ft_bg:=i>0 ? "0":"_"
  596. return
  597.  
  598. ft_GetThreshold(pp)
  599. {
  600. IP:=IS:=0
  601. Loop, 256
  602. k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
  603. NewThreshold:=Floor(IP/IS)
  604. Loop, 20 {
  605. Threshold:=NewThreshold
  606. IP1:=IS1:=0
  607. Loop, % Threshold+1
  608. k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
  609. IP2:=IP-IP1, IS2:=IS-IS1
  610. if (IS1!=0 and IS2!=0)
  611. NewThreshold:=Floor((IP1/IS1+IP2/IS2)/2)
  612. if (NewThreshold=Threshold)
  613. Break
  614. }
  615. return, NewThreshold
  616. }
  617.  
  618. ft_GrayDiff2Two:
  619. GuiControlGet, ft_GrayDiff
  620. if (ft_GrayDiff="")
  621. {
  622. MsgBox, 4096, Tip
  623. , `n Please Set Gray Difference First ! `n, 1
  624. Return
  625. }
  626. if (ft_left=ft_cors.LeftCut)
  627. Gosub, ft_LeftCut
  628. if (ft_right=ft_cors.RightCut)
  629. Gosub, ft_RightCut
  630. if (ft_up=ft_cors.UpCut)
  631. Gosub, ft_UpCut
  632. if (ft_down=ft_cors.DownCut)
  633. Gosub, ft_DownCut
  634. ft_GrayDiff:=Round(ft_GrayDiff)
  635. ft_color:="**" ft_GrayDiff, k:=i:=0, n:=ft_nW
  636. Loop, % ft_nW*ft_nH {
  637. if (ft_ascii[++k]="")
  638. Continue
  639. j:=ft_gs[k]+ft_GrayDiff
  640. if ( ft_gs[k-1]>j or ft_gs[k+1]>j
  641. or ft_gs[k-n]>j or ft_gs[k+n]>j
  642. or ft_gs[k-n-1]>j or ft_gs[k-n+1]>j
  643. or ft_gs[k+n-1]>j or ft_gs[k+n+1]>j )
  644. ft_ascii[k]:="0", c:="Black", i++
  645. else
  646. ft_ascii[k]:="_", c:="White", i--
  647. Gosub, ft_SetColor
  648. }
  649. ft_bg:=i>0 ? "0":"_"
  650. return
  651.  
  652. ft_Color2Two:
  653. ft_ColorPos2Two:
  654. GuiControlGet, c,, ft_SelColor
  655. if (c="")
  656. {
  657. MsgBox, 4096, Tip
  658. , `n Please Select a Color First ! `n, 1
  659. return
  660. }
  661. ft_UsePos:=InStr(A_ThisLabel,"ColorPos2Two") ? 1:0
  662. GuiControlGet, n,, ft_Similar
  663. n:=Round(n/100,2), ft_color:=c "@" n
  664. n:=Floor(9*255*255*(1-n)*(1-n)), k:=i:=0
  665. ft_rr:=(c>>16)&0xFF, ft_gg:=(c>>8)&0xFF, ft_bb:=c&0xFF
  666. Loop, % ft_nW*ft_nH {
  667. if (ft_ascii[++k]="")
  668. Continue
  669. c:=ft_cors[k], r:=((c>>16)&0xFF)-ft_rr
  670. , g:=((c>>8)&0xFF)-ft_gg, b:=(c&0xFF)-ft_bb
  671. if (3*r*r+4*g*g+2*b*b<=n)
  672. ft_ascii[k]:="0", c:="Black", i++
  673. else
  674. ft_ascii[k]:="_", c:="White", i--
  675. Gosub, ft_SetColor
  676. }
  677. ft_bg:=i>0 ? "0":"_"
  678. return
  679.  
  680. ft_ColorDiff2Two:
  681. GuiControlGet, c,, ft_SelColor
  682. if (c="")
  683. {
  684. MsgBox, 4096, Tip
  685. , `n Please Select a Color First ! `n, 1
  686. return
  687. }
  688. GuiControlGet, ft_dR
  689. GuiControlGet, ft_dG
  690. GuiControlGet, ft_dB
  691. ft_rr:=(c>>16)&0xFF, ft_gg:=(c>>8)&0xFF, ft_bb:=c&0xFF
  692. n:=Format("{:06X}",(ft_dR<<16)|(ft_dG<<8)|ft_dB)
  693. ft_color:=StrReplace(c "-" n,"0x"), k:=i:=0
  694. Loop, % ft_nW*ft_nH {
  695. if (ft_ascii[++k]="")
  696. Continue
  697. c:=ft_cors[k], r:=(c>>16)&0xFF, g:=(c>>8)&0xFF, b:=c&0xFF
  698. if ( Abs(r-ft_rr)<=ft_dR
  699. and Abs(g-ft_gg)<=ft_dG
  700. and Abs(b-ft_bb)<=ft_dB )
  701. ft_ascii[k]:="0", c:="Black", i++
  702. else
  703. ft_ascii[k]:="_", c:="White", i--
  704. Gosub, ft_SetColor
  705. }
  706. ft_bg:=i>0 ? "0":"_"
  707. return
  708.  
  709. ft_gui_del:
  710. ft_ascii[k]:="", c:=ft_WindowColor
  711. Gosub, ft_SetColor
  712. return
  713.  
  714. ft_LeftCut3:
  715. Loop, 3
  716. Gosub, ft_LeftCut
  717. return
  718.  
  719. ft_LeftCut:
  720. if (ft_left+ft_right>=ft_nW)
  721. return
  722. ft_left++, k:=ft_left
  723. Loop, %ft_nH% {
  724. Gosub, ft_gui_del
  725. k+=ft_nW
  726. }
  727. return
  728.  
  729. ft_RightCut3:
  730. Loop, 3
  731. Gosub, ft_RightCut
  732. return
  733.  
  734. ft_RightCut:
  735. if (ft_left+ft_right>=ft_nW)
  736. return
  737. ft_right++, k:=ft_nW+1-ft_right
  738. Loop, %ft_nH% {
  739. Gosub, ft_gui_del
  740. k+=ft_nW
  741. }
  742. return
  743.  
  744. ft_UpCut3:
  745. Loop, 3
  746. Gosub, ft_UpCut
  747. return
  748.  
  749. ft_UpCut:
  750. if (ft_up+ft_down>=ft_nH)
  751. return
  752. ft_up++, k:=(ft_up-1)*ft_nW
  753. Loop, %ft_nW% {
  754. k++
  755. Gosub, ft_gui_del
  756. }
  757. return
  758.  
  759. ft_DownCut3:
  760. Loop, 3
  761. Gosub, ft_DownCut
  762. return
  763.  
  764. ft_DownCut:
  765. if (ft_up+ft_down>=ft_nH)
  766. return
  767. ft_down++, k:=(ft_nH-ft_down)*ft_nW
  768. Loop, %ft_nW% {
  769. k++
  770. Gosub, ft_gui_del
  771. }
  772. return
  773.  
  774. ft_getwz:
  775. ft_wz:=""
  776. if (ft_bg="")
  777. return
  778. k:=0
  779. Loop, %ft_nH% {
  780. v:=""
  781. Loop, %ft_nW%
  782. v.=ft_ascii[++k]
  783. ft_wz.=v="" ? "" : v "`n"
  784. }
  785. return
  786.  
  787. ft_Auto:
  788. Gosub, ft_getwz
  789. if (ft_wz="")
  790. {
  791. MsgBox, 4096, Tip
  792. , `nPlease Click Color2Two or Gray2Two First !, 1
  793. return
  794. }
  795. While InStr(ft_wz, ft_bg) {
  796. if (ft_wz~="^" ft_bg "+\n")
  797. {
  798. ft_wz:=RegExReplace(ft_wz,"^" ft_bg "+\n")
  799. Gosub, ft_UpCut
  800. }
  801. else if !(ft_wz~="m`n)[^\n" ft_bg "]$")
  802. {
  803. ft_wz:=RegExReplace(ft_wz,"m`n)" ft_bg "$")
  804. Gosub, ft_RightCut
  805. }
  806. else if (ft_wz~="\n" ft_bg "+\n$")
  807. {
  808. ft_wz:=RegExReplace(ft_wz,"\n\K" ft_bg "+\n$")
  809. Gosub, ft_DownCut
  810. }
  811. else if !(ft_wz~="m`n)^[^\n" ft_bg "]")
  812. {
  813. ft_wz:=RegExReplace(ft_wz,"m`n)^" ft_bg)
  814. Gosub, ft_LeftCut
  815. }
  816. else Break
  817. }
  818. ft_wz:=""
  819. return
  820.  
  821. ft_OK:
  822. ft_AllAdd:
  823. ft_SplitAdd:
  824. Gosub, ft_getwz
  825. if ft_wz=
  826. {
  827. MsgBox, 4096, Tip
  828. , `nPlease Click Color2Two or Gray2Two First !, 1
  829. return
  830. }
  831. if InStr(ft_color,"@") and (ft_UsePos)
  832. {
  833. StringSplit, r, ft_color, @
  834. k:=i:=j:=0
  835. Loop, % ft_nW*ft_nH {
  836. if (ft_ascii[++k]="")
  837. Continue
  838. i++
  839. if (k=ft_cors.SelPos)
  840. {
  841. j:=i
  842. Break
  843. }
  844. }
  845. if (j=0)
  846. {
  847. MsgBox, 4096, Tip
  848. , Please select the core color again !, 3
  849. return
  850. }
  851. ft_color:="#" . j . "@" . r2
  852. }
  853. GuiControlGet, ft_Comment
  854. ft_cors.Event:=A_ThisLabel
  855. if InStr(A_ThisLabel, "SplitAdd")
  856. {
  857. if InStr(ft_color,"#")
  858. {
  859. MsgBox, 4096, Tip
  860. , % "Can't be used in ColorPos mode, "
  861. . "because it can cause position errors", 3
  862. return
  863. }
  864. SetFormat, IntegerFast, d
  865. ft_bg:=StrLen(StrReplace(ft_wz,"_"))
  866. > StrLen(StrReplace(ft_wz,"0")) ? "0":"_"
  867. s:="", k:=ft_nW*ft_nH+1+ft_left
  868. , i:=0, w:=ft_nW-ft_left-ft_right
  869. Loop, % w {
  870. i++
  871. GuiControlGet, j,, % ft_C_[k++]
  872. if (j=0 and A_Index<w)
  873. Continue
  874. v:=RegExReplace(ft_wz,"m`n)^(.{" i "}).*","$1")
  875. ft_wz:=RegExReplace(ft_wz,"m`n)^.{" i "}"), i:=0
  876. While InStr(v, ft_bg) {
  877. if (v~="^" ft_bg "+\n")
  878. v:=RegExReplace(v,"^" ft_bg "+\n")
  879. else if !(v~="m`n)[^\n" ft_bg "]$")
  880. v:=RegExReplace(v,"m`n)" ft_bg "$")
  881. else if (v~="\n" ft_bg "+\n$")
  882. v:=RegExReplace(v,"\n\K" ft_bg "+\n$")
  883. else if !(v~="m`n)^[^\n" ft_bg "]")
  884. v:=RegExReplace(v,"m`n)^" ft_bg)
  885. else Break
  886. }
  887. if v!=
  888. s.=ft_towz(ft_color, v, SubStr(ft_Comment,1,1))
  889. ft_Comment:=SubStr(ft_Comment, 2)
  890. }
  891. ft_cors.Result:=s
  892. Gui, Hide
  893. return
  894. }
  895. s:=ft_towz(ft_color, ft_wz, ft_Comment)
  896. if InStr(A_ThisLabel, "AllAdd")
  897. {
  898. ft_cors.Result:=s
  899. Gui, Hide
  900. return
  901. }
  902. x:=ft_px-ft_ww+ft_left+(ft_nW-ft_left-ft_right)//2
  903. y:=ft_py-ft_hh+ft_up+(ft_nH-ft_up-ft_down)//2
  904. s:=StrReplace(s, "Text.=", "Text:=")
  905. s=
  906. (
  907. t1:=A_TickCount
  908. %s%
  909. if (ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Text))
  910. {
  911. CoordMode, Mouse
  912. X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
  913. ; Click, `%X`%, `%Y`%
  914. }
  915.  
  916. MsgBox, 4096, `% ok.MaxIndex(), `% "Time:``t" (A_TickCount-t1) " ms``n``n"
  917. . "Pos:``t[%x%, %y%] " X ", " Y "``n``n"
  918. . "Result:``t" (ok ? "Success ! " Comment : "Failed !")
  919.  
  920. for i,v in ok
  921. if i<=2
  922. MouseTip(v.1+v.3//2, v.2+v.4//2)
  923.  
  924. )
  925. ft_cors.Result:=s
  926. Gui, Hide
  927. return
  928.  
  929. ft_towz(color,wz,comment="")
  930. {
  931. SetFormat, IntegerFast, d
  932. wz:=StrReplace(StrReplace(wz,"0","1"),"_","0")
  933. wz:=(InStr(wz,"`n")-1) "." bit2base64(wz)
  934. return, "`nText.=""|<" comment ">" color "$" wz """`n"
  935. }
  936.  
  937. ft_add(s, rn=1)
  938. {
  939. global ft_hscr
  940. if (rn=1)
  941. s:="`n" s "`n"
  942. s:=RegExReplace(s,"\R","`r`n")
  943. ControlGet, i, CurrentCol,,, ahk_id %ft_hscr%
  944. if i>1
  945. ControlSend,, {Home}{Down}, ahk_id %ft_hscr%
  946. Control, EditPaste, %s%,, ahk_id %ft_hscr%
  947. }
  948.  
  949. ft_End:
  950. Trim("")
  951.  
  952.  
  953. ;===== Copy The Following Functions To Your Own Code Just once =====
  954.  
  955.  
  956. ;--------------------------------
  957. ; FindText - Capture screen image into text and then find it
  958. ;--------------------------------
  959. ; X, Y --> the search scope's upper left corner coordinates
  960. ; W, H --> the search scope's Width and Height
  961. ; err1, err0 --> character "0" or "_" fault-tolerant in percentage
  962. ; Text --> can be a lot of text parsed into images, separated by "|"
  963. ; ScreenShot --> if the value is 0, the last screenshot will be used
  964. ; FindAll --> if the value is 0, Just find one result and return
  965. ; JoinText --> if the value is 1, Join all Text for combination lookup
  966. ; offsetX, offsetY --> Set the Max text offset for combination lookup
  967. ; ruturn --> a second-order array contains the [X,Y,W,H,Comment] of Each Find
  968. ;--------------------------------
  969.  
  970. FindText( x, y, w, h, err1, err0, text, ScreenShot=1
  971. , FindAll=1, JoinText=0, offsetX=20, offsetY=10 )
  972. {
  973. xywh2xywh(x,y,w,h,x,y,w,h)
  974. if (w<1 or h<1)
  975. return, 0
  976. bch:=A_BatchLines
  977. SetBatchLines, -1
  978. ;-------------------------------
  979. GetBitsFromScreen(x,y,w,h,Scan0,Stride,ScreenShot,zx,zy)
  980. ;-------------------------------
  981. sx:=x-zx, sy:=y-zy, sw:=w, sh:=h
  982. , arr:=[], info:=[], allv:=""
  983. Loop, Parse, text, |
  984. {
  985. v:=A_LoopField
  986. IfNotInString, v, $, Continue
  987. comment:="", e1:=err1, e0:=err0
  988. ; You Can Add Comment Text within The <>
  989. if RegExMatch(v,"<([^>]*)>",r)
  990. v:=StrReplace(v,r), comment:=Trim(r1)
  991. ; You can Add two fault-tolerant in the [], separated by commas
  992. if RegExMatch(v,"\[([^\]]*)]",r)
  993. {
  994. v:=StrReplace(v,r), r1.=","
  995. StringSplit, r, r1, `,
  996. e1:=r1, e0:=r2
  997. }
  998. StringSplit, r, v, $
  999. color:=r1, v:=r2
  1000. StringSplit, r, v, .
  1001. w1:=r1, v:=base64tobit(r2), h1:=StrLen(v)//w1
  1002. if (r0<2 or h1<1 or w1>sw or h1>sh or StrLen(v)!=w1*h1)
  1003. Continue
  1004. mode:=InStr(color,"-") ? 4 : InStr(color,"#") ? 3
  1005. : InStr(color,"**") ? 2 : InStr(color,"*") ? 1 : 0
  1006. if (mode=4)
  1007. {
  1008. color:=StrReplace(color,"0x")
  1009. StringSplit, r, color, -
  1010. color:="0x" . r1, n:="0x" . r2
  1011. }
  1012. else
  1013. {
  1014. color:=RegExReplace(color,"[*#]") . "@"
  1015. StringSplit, r, color, @
  1016. color:=mode=3 ? ((r1-1)//w1)*Stride+Mod(r1-1,w1)*4 : r1
  1017. n:=Round(r2,2)+(!r2), n:=Floor(9*255*255*(1-n)*(1-n))
  1018. }
  1019. StrReplace(v,"1","",len1), len0:=StrLen(v)-len1
  1020. e1:=Round(len1*e1), e0:=Round(len0*e0)
  1021. info.Push( [StrLen(allv),w1,h1,len1,len0,e1,e0
  1022. ,mode,color,n,comment] ), allv.=v
  1023. }
  1024. if (allv="")
  1025. {
  1026. SetBatchLines, %bch%
  1027. return, 0
  1028. }
  1029. num:=info.MaxIndex(), VarSetCapacity(input, num*7*4)
  1030. , VarSetCapacity(gs, sw*sh)
  1031. , VarSetCapacity(ss, sw*sh), k:=StrLen(allv)*4
  1032. , VarSetCapacity(s1, k), VarSetCapacity(s0, k)
  1033. , allpos_max:=FindAll ? 1024 : 1
  1034. , VarSetCapacity(allpos, allpos_max*4)
  1035. ;-------------------------------------
  1036. Loop, 2 {
  1037. if (JoinText)
  1038. {
  1039. mode:=info.1.8, color:=info.1.9, n:=info.1.10
  1040. , w1:=-1, h1:=info.1.3, comment:="", k:=0
  1041. Loop, % num {
  1042. i:=A_Index, w1+=info[i].2+1, comment.=info[i].11
  1043. Loop, 7
  1044. NumPut(info[i][A_Index], input, 4*(k++), "int")
  1045. }
  1046. ok:=PicFind( mode,color,n,offsetX,offsetY
  1047. ,Scan0,Stride,sx,sy,sw,sh,gs,ss,allv,s1,s0
  1048. ,input,num*7,allpos,allpos_max )
  1049. Loop, % ok
  1050. pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  1051. , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  1052. , arr.Push( [rx,ry,w1,h1,comment] )
  1053. }
  1054. else
  1055. {
  1056. For i,j in info
  1057. {
  1058. mode:=j.8, color:=j.9, n:=j.10, comment:=j.11
  1059. , w1:=j.2, h1:=j.3, v:=SubStr(allv, j.1+1, w1*h1)
  1060. Loop, 7
  1061. NumPut(j[A_Index], input, 4*(A_Index-1), "int")
  1062. NumPut(0, input, "int")
  1063. ok:=PicFind( mode,color,n,offsetX,offsetY
  1064. ,Scan0,Stride,sx,sy,sw,sh,gs,ss,v,s1,s0
  1065. ,input,7,allpos,allpos_max )
  1066. Loop, % ok
  1067. pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  1068. , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  1069. , arr.Push( [rx,ry,w1,h1,comment] )
  1070. }
  1071. }
  1072. if (err1=0 and err0=0 and !arr.MaxIndex())
  1073. {
  1074. err1:=err0:=0.1
  1075. For i,j in info
  1076. if (j.6=0 and j.7=0)
  1077. j.6:=Round(j.4*err1), j.7:=Round(j.5*err0)
  1078. }
  1079. else Break
  1080. }
  1081. SetBatchLines, %bch%
  1082. return, arr.MaxIndex() ? arr:0
  1083. }
  1084.  
  1085. PicFind(mode, color, n, offsetX, offsetY
  1086. , Scan0, Stride, sx, sy, sw, sh
  1087. , ByRef gs, ByRef ss, ByRef text, ByRef s1, ByRef s0
  1088. , ByRef input, num, ByRef allpos, allpos_max)
  1089. {
  1090. static MyFunc, Ptr:=A_PtrSize ? "UPtr" : "UInt"
  1091. if !MyFunc
  1092. {
  1093. x32:="5557565383EC788B8424CC0000008BBC24CC000000C7442"
  1094. . "424000000008B40048B7F148944243C8B8424CC000000897C2"
  1095. . "42C8BBC24CC0000008B40088B7F18894424348B8424CC00000"
  1096. . "0897C24308B400C89C6894424288B8424CC0000008B401039C"
  1097. . "6894424200F4DC68944241C8B8424D000000085C00F8E15010"
  1098. . "0008BB424CC0000008B44242489F78B0C868B7486048B44870"
  1099. . "88974241085C0894424180F8ED700000089CD894C2414C7442"
  1100. . "40C00000000C744240800000000C744240400000000890C248"
  1101. . "D76008DBC27000000008B5C24108B7424088B4C24148B54240"
  1102. . "C89DF89F029F101F78BB424C000000001CE85DB7E5E8B0C248"
  1103. . "9EB893C2489D7EB198BAC24C800000083C70483C00189548D0"
  1104. . "083C101390424742C83BC248C0000000389FA0F45D0803C063"
  1105. . "175D48BAC24C400000083C70483C00189549D0083C30139042"
  1106. . "475D48B7424100174241489DD890C2483442404018BB424B00"
  1107. . "000008B442404017424088BBC24A4000000017C240C3944241"
  1108. . "80F8554FFFFFF83442424078B442424398424D00000000F8FE"
  1109. . "BFEFFFF83BC248C000000030F84A00600008B8424A40000008"
  1110. . "BB424A80000000FAF8424AC0000008BBC248C0000008D2CB08"
  1111. . "B8424B00000008BB424A4000000F7D885FF8D0486894424100"
  1112. . "F84F702000083BC248C000000010F845F08000083BC248C000"
  1113. . "000020F84130900008B8424900000008B9C24940000000FB6B"
  1114. . "C24940000000FB6B42490000000C744241800000000C744242"
  1115. . "400000000C1E8100FB6DF0FB6D08B84249000000089D10FB6C"
  1116. . "4894424088B842494000000C1E8100FB6C029C101D08904248"
  1117. . "B442408894C24408B4C240801D829D9894424088D043E894C2"
  1118. . "40489F129F9894424148BBC24B40000008B8424B0000000894"
  1119. . "C240C89E98B6C2440C1E00285FF894424380F8EBA0000008BB"
  1120. . "424B000000085F60F8E910000008B8424A00000008B5424240"
  1121. . "39424BC00000001C8034C243889CF894C244003BC24A000000"
  1122. . "0EB3D8D76008DBC2700000000391C247C3D394C24047F37394"
  1123. . "C24087C3189F30FB6F33974240C0F9EC3397424140F9DC183C"
  1124. . "00483C20121D9884AFF39F8741E0FB658020FB648010FB6303"
  1125. . "9DD7EBE31C983C00483C201884AFF39F875E28BBC24B000000"
  1126. . "0017C24248B4C24408344241801034C24108B442418398424B"
  1127. . "40000000F8546FFFFFF8B8424B00000002B44243C8944240C8"
  1128. . "B8424B40000002B442434894424600F884D0900008B4424288"
  1129. . "BBC24C40000008B74243CC744241000000000C744243800000"
  1130. . "000C7442434000000008D3C8789C583EE01897C246C8974247"
  1131. . "48B44240C85C00F88E70000008B7C24388B8424AC000000BE0"
  1132. . "0000000C704240000000001F8C1E0108944246889F82B84249"
  1133. . "C0000000F49F08B84249C000000897424640FAFB424B000000"
  1134. . "001F8894424708974245C8DB6000000008B04240344241089C"
  1135. . "1894424088B442430394424200F84AA0100008B5C241C89C60"
  1136. . "38C24BC00000031C08B54242C85DB0F8EC8010000897424048"
  1137. . "B7C2420EB2D39C77E1C8BB424C80000008B1C8601CB803B007"
  1138. . "40B836C240401782B8D74260083C0013944241C0F849101000"
  1139. . "039C57ECF8BB424C40000008B1C8601CB803B0174BE83EA017"
  1140. . "9B9830424018B04243944240C0F8D68FFFFFF83442438018BB"
  1141. . "424B00000008B44243801742410394424600F8DEFFEFFFF8B4"
  1142. . "C243483C47889C85B5E5F5DC250008B8424900000008BB424B"
  1143. . "4000000C744240C00000000C744241400000000C1E8100FB6C"
  1144. . "08904248B8424900000000FB6C4894424040FB684249000000"
  1145. . "0894424088B8424B0000000C1E00285F68944242489E88BAC2"
  1146. . "4940000000F8E24FEFFFF8B9C24B000000085DB7E758B9C24A"
  1147. . "00000008B7424148BBC24A000000003B424BC00000001C3034"
  1148. . "424248944241801C78D76008DBC27000000000FB643020FB64"
  1149. . "B012B04242B4C24040FB6132B5424080FAFC00FAFC98D04400"
  1150. . "FAFD28D04888D045039C50F930683C30483C60139DF75C98BB"
  1151. . "C24B0000000017C24148B4424188344240C01034424108B742"
  1152. . "40C39B424B40000000F8566FFFFFFE985FDFFFF85ED7E358B7"
  1153. . "424088BBC24BC00000031C08B54242C8D1C378BB424C400000"
  1154. . "08B0C8601D9803901740983EA010F8890FEFFFF83C00139C57"
  1155. . "5E683BC24D0000000070F8EAA0100008B442474030424C7442"
  1156. . "44007000000896C2444894424288B8424CC00000083C020894"
  1157. . "4243C8B44243C8B9424B00000008B7C24288B0029C28944245"
  1158. . "08B84249800000001F839C20F4EC289C68944244C39FE0F8C0"
  1159. . "90100008B44243C8B700C8B78148B6808897424148B7010897"
  1160. . "C245489C7897424248BB424B40000002B700489F08B7424703"
  1161. . "9C60F4EC68BB424C4000000894424188B47FC89442404C1E00"
  1162. . "201C6038424C8000000894424588B4424648B7C2428037C245"
  1163. . "C3B442418894424040F8F8700000085ED7E268B8C24BC00000"
  1164. . "08B54242431C08D1C398B0C8601D9803901740583EA01784A8"
  1165. . "3C00139C575EA8B4424148B4C245439C8747E85C07E7A8B9C2"
  1166. . "4BC000000896C244831C08B6C245801FBEB0983C0013944241"
  1167. . "4745C8B54850001DA803A0074EC83E90179E78B6C244890834"
  1168. . "424040103BC24B00000008B442404394424180F8D79FFFFFF8"
  1169. . "3442428018B4424283944244C0F8D4CFFFFFF830424018B6C2"
  1170. . "4448B04243944240C0F8D7EFCFFFFE911FDFFFF8B4424288B7"
  1171. . "4245083442440078344243C1C8D4430FF894424288B4424403"
  1172. . "98424D00000000F8F7FFEFFFF8B6C24448B7C24348B0424038"
  1173. . "424A80000008BB424D40000000B4424688D4F01398C24D8000"
  1174. . "0008904BE0F8ED8FCFFFF85ED7E278B7424088BBC24BC00000"
  1175. . "08B8424C40000008D1C378B74246C8B1083C00401DA39F0C60"
  1176. . "20075F283042401894C24348B04243944240C0F8DDEFBFFFFE"
  1177. . "971FCFFFF89F68DBC27000000008B8424B0000000038424A80"
  1178. . "000002B44243C894424248B8424AC000000038424B40000002"
  1179. . "B442434398424AC000000894424380F8F520400008B8424A40"
  1180. . "000008BB424A80000000FAF8424AC000000C74424180000000"
  1181. . "08D04B0038424900000008BB424A0000000894424348B44242"
  1182. . "4398424A80000000F8F2B0100008B8424AC000000C1E010894"
  1183. . "4243C8B442434894424148B8424A8000000894424088B44241"
  1184. . "40FB67C060289C52BAC2490000000893C240FB67C0601897C2"
  1185. . "4040FB63C068B44241C85C00F8E140100008B4424308944241"
  1186. . "08B44242C8944240C31C0EB5D394424207E4A8B9C24C800000"
  1187. . "08B0C8301E90FB6540E020FB65C0E012B14242B5C24040FB60"
  1188. . "C0E0FAFD20FAFDB29F98D14520FAFC98D149A8D144A3994249"
  1189. . "4000000720C836C2410017865908D74260083C0013944241C0"
  1190. . "F84A3000000394424287E9D8B9C24C40000008B0C8301E90FB"
  1191. . "6540E020FB65C0E012B14242B5C24040FB60C0E0FAFD20FAFD"
  1192. . "B29F98D14520FAFC98D149A8D144A3B9424940000000F865BF"
  1193. . "FFFFF836C240C010F8950FFFFFF834424080183442414048B4"
  1194. . "42408394424240F8DF6FEFFFF838424AC000000018BBC24A40"
  1195. . "000008B442438017C24343B8424AC0000000F8DA0FEFFFF8B4"
  1196. . "C241883C4785B5E89C85F5DC250008D7426008B7C24188B442"
  1197. . "43C0B4424088B9C24D40000008D4F013B8C24D80000008904B"
  1198. . "B0F8D84FAFFFF894C2418EB848B8424900000008B8C24B4000"
  1199. . "000C7042400000000C74424040000000083C001C1E00789C78"
  1200. . "B8424B0000000C1E00285C98944240889E889FD0F8ECFF8FFF"
  1201. . "F8B9424B000000085D27E5F8B8C24A00000008B5C2404039C2"
  1202. . "4BC00000001C1034424088944240C038424A000000089C70FB"
  1203. . "651020FB641010FB6316BC04B6BD22601C289F0C1E00429F00"
  1204. . "1D039C50F970383C10483C30139F975D58BBC24B0000000017"
  1205. . "C24048B44240C83042401034424108B342439B424B40000007"
  1206. . "582E94CF8FFFF8B8424B0000000C7042400000000C74424040"
  1207. . "0000000C1E002894424088B8424B400000085C00F8E9200000"
  1208. . "08B8424B000000085C07E6F8B8C24A00000008B5C24048BB42"
  1209. . "4B800000001E9036C240801DE039C24BC000000896C240C03A"
  1210. . "C24A00000000FB651020FB6410183C1040FB679FC83C60183C"
  1211. . "3016BC04B6BD22601C289F8C1E00429F801D0C1F8078846FFC"
  1212. . "643FF0039CD75CC8BB424B0000000017424048B6C240C83042"
  1213. . "401036C24108B0424398424B40000000F856EFFFFFF83BC24B"
  1214. . "4000000020F8E80F7FFFF8B8424BC000000038424B00000008"
  1215. . "BAC24B800000003AC24B0000000C7442404010000008944240"
  1216. . "88B8424B400000083E8018944240C8B8424B000000083C0018"
  1217. . "944241083BC24B0000000027E798B44241089E92B8C24B0000"
  1218. . "0008B5C240889EA8D34288D45FE8904240FB642010FB63A038"
  1219. . "4249000000039F87C360FB67A0239F87C2E0FB6790139F87C2"
  1220. . "60FB63E39F87C1F0FB63939F87C180FB6790239F87C100FB67"
  1221. . "EFF39F87C080FB67E0139F87D04C643010183C20183C30183C"
  1222. . "10183C6013B0C2475A3834424040103AC24B00000008B44240"
  1223. . "48BB424B0000000017424083944240C0F8558FFFFFFE98FF6F"
  1224. . "FFF83C47831C95B89C85E5F5DC2500090909090909090"
  1225. x64:="4157415641554154555756534881EC88000000488B84245"
  1226. . "0010000488BB42450010000448B94245801000089542428448"
  1227. . "944240844898C24E80000008B40048B76144C8BBC244001000"
  1228. . "04C8BB42448010000C74424180000000089442430488B84245"
  1229. . "00100008974241C488BB424500100008B40088B76188944243"
  1230. . "C488B842450010000897424388B400C89C789442440488B842"
  1231. . "4500100008B401039C7894424100F4DC74585D289442454488"
  1232. . "B84245001000048894424200F8ECB000000488B442420448B0"
  1233. . "8448B68048B400885C0894424040F8E940000004489CE44890"
  1234. . "C244531E431FF31ED0F1F8400000000004585ED7E614863142"
  1235. . "4418D5C3D0089F848039424380100004589E0EB1D0F1F0083C"
  1236. . "0014D63D94183C0044183C1014883C20139C34789149E74288"
  1237. . "3F9034589C2440F45D0803A3175D783C0014C63DE4183C0048"
  1238. . "3C6014883C20139C34789149F75D844012C2483C50103BC241"
  1239. . "80100004403A42400010000396C24047582834424180748834"
  1240. . "424201C8B442418398424580100000F8F35FFFFFF83F9030F8"
  1241. . "43D0600008B8424000100008BBC24080100000FAF842410010"
  1242. . "0008BB424000100008D3CB88B842418010000F7D885C9448D2"
  1243. . "C860F841101000083F9010F842008000083F9020F84BF08000"
  1244. . "08B742428C744240400000000C74424180000000089F0440FB"
  1245. . "6CEC1E8104589CC0FB6D84889F08B7424080FB6D44189DB89F"
  1246. . "0440FB6C64889F1C1E8100FB6CD89D60FB6C08D2C0A8B94242"
  1247. . "00100004129C301C3438D040129CE4529C48904248B8424180"
  1248. . "10000C1E00285D2894424080F8E660100004C89BC244001000"
  1249. . "0448BBC24180100004585FF0F8E91040000488B8C24F800000"
  1250. . "04863C74C6354241831D24C03942430010000488D440102EB3"
  1251. . "A0F1F80000000004439C37C4039CE7F3C39CD7C384539CC410"
  1252. . "F9EC044390C240F9DC14421C141880C124883C2014883C0044"
  1253. . "139D70F8E2D040000440FB6000FB648FF440FB648FE4539C37"
  1254. . "EBB31C9EBD58B5C2428448B8C242001000031ED4531E44889D"
  1255. . "84189DB0FB6DB0FB6F48B84241801000041C1EB10450FB6DBC"
  1256. . "1E0024585C98904240F8EA10000004C89BC24400100004C89B"
  1257. . "42448010000448B7C2408448BB424180100004585F67E60488"
  1258. . "B8C24F80000004D63D44C039424300100004863C74531C94C8"
  1259. . "D440102410FB600410FB648FF410FB650FE4429D829F10FAFC"
  1260. . "029DA0FAFC98D04400FAFD28D04888D04504139C7430F93040"
  1261. . "A4983C1014983C0044539CE7FC4033C244501F483C5014401E"
  1262. . "F39AC2420010000758C4C8BBC24400100004C8BB4244801000"
  1263. . "08B8424180100002B4424308904248B8424200100002B44243"
  1264. . "C894424680F88540800008B7C24404D89F5488BAC243001000"
  1265. . "0448B7424104C89FEC74424040000000048C74424280000000"
  1266. . "0C74424200000000089F883E801498D4487044189FF4889442"
  1267. . "4088B44243083E801894424788B042485C00F88D9000000488"
  1268. . "B5C24288B8424100100004D89EC448B6C245401D8C1E010894"
  1269. . "4247089D82B8424F000000089C7B8000000000F49C731FF894"
  1270. . "4246C0FAF842418010000894424648B8424F000000001D8894"
  1271. . "42474908B442404897C24188D1C388B4424384139C60F84AB0"
  1272. . "000004189C131C04585ED448B44241C7F36E9C30000000F1F4"
  1273. . "0004139CE7E1B418B148401DA4863D2807C150000740B4183E"
  1274. . "901782E0F1F4400004883C0014139C50F8E920000004139C78"
  1275. . "9C17ECC8B148601DA4863D2807C15000174BD4183E80179B74"
  1276. . "883C701393C240F8D7AFFFFFF4D89E54883442428018B9C241"
  1277. . "8010000488B442428015C2404394424680F8DFCFEFFFF8B4C2"
  1278. . "42089C84881C4880000005B5E5F5D415C415D415E415FC3458"
  1279. . "5FF7E278B4C241C4C8B4424084889F28B0201D84898807C050"
  1280. . "001740583E90178934883C2044939D075E583BC24580100000"
  1281. . "70F8EE60100008B442478488B8C24500100000344241844896"
  1282. . "C2450448BAC241801000044897C24404883C1204889742410C"
  1283. . "744243C07000000448974244448897C24484989CF895C247C8"
  1284. . "9C64C89642430418B074489EA29C28944245C8B8424E800000"
  1285. . "001F039C20F4EC239F0894424580F8CD0000000418B47148BB"
  1286. . "C2420010000412B7F0449635FFC458B4F08458B670C8944246"
  1287. . "08B442474458B771039C70F4FF8488B44241048C1E3024C8D1"
  1288. . "41848035C24308B442464448D04068B44246C39F84189C37F7"
  1289. . "2904585C97E234489F131D2418B04924401C04898807C05000"
  1290. . "1740583E90178464883C2014139D17FE28B4424604139C40F8"
  1291. . "4AA0000004585E40F8EA100000089C131D2EB0D4883C201413"
  1292. . "9D40F8E8E0000008B04934401C04898807C05000074E483E90"
  1293. . "179DF4183C3014501E84439DF7D8F83C601397424580F8D6EF"
  1294. . "FFFFF488B7C2448448B7C2440448B742444448B6C2450488B7"
  1295. . "424104C8B6424304883C701393C240F8D97FDFFFFE918FEFFF"
  1296. . "F6690037C240844017C241883442404014401EF8B442404398"
  1297. . "424200100000F854DFBFFFF4C8BBC2440010000E996FCFFFF8"
  1298. . "B44245C8344243C074983C71C8D7406FF8B44243C398424580"
  1299. . "100000F8F87FEFFFF448B7C2440448B742444448B6C2450488"
  1300. . "B7C24488B5C247C488B7424104C8B64243048634424208B542"
  1301. . "418039424080100004C8B9C24600100000B5424708D4801398"
  1302. . "C2468010000418914830F8E9AFDFFFF4585FF7E1D4C8B44240"
  1303. . "84889F08B104883C00401DA4C39C04863D2C64415000075EB4"
  1304. . "883C701393C24894C24200F8DBAFCFFFFE93BFDFFFF0F1F440"
  1305. . "0008B842418010000038424080100002B442430894424308B8"
  1306. . "42410010000038424200100002B44243C39842410010000894"
  1307. . "424440F8F230400008B8424000100008BBC24080100000FAF8"
  1308. . "42410010000448B642440448B6C24544C8B8C24F8000000C74"
  1309. . "42420000000008D04B8034424288944243C8B4424303984240"
  1310. . "80100000F8F2F0100008B8424100100008B6C243CC1E010894"
  1311. . "424408B8424080100008904248D450289EF2B7C24284585ED4"
  1312. . "898450FB61C018D45014898410FB61C014863C5410FB634010"
  1313. . "F8E140100008B442438894424188B44241C8944240431C0EB6"
  1314. . "244395424107E4E418B0C8601F98D5102448D41014863C9410"
  1315. . "FB60C094863D24D63C0410FB61411470FB6040129F10FAFC94"
  1316. . "429DA4129D80FAFD2450FAFC08D1452428D14828D144A39542"
  1317. . "4087207836C241801786B4883C0014139C50F8E9E000000413"
  1318. . "9C44189C27E96418B0C8701F98D5102448D41014863C9410FB"
  1319. . "60C094863D24D63C0410FB61411470FB6040129F10FAFC9442"
  1320. . "9DA4129D80FAFD2450FAFC08D1452428D14828D144A3B54240"
  1321. . "80F864BFFFFFF836C2404010F8940FFFFFF8304240183C5048"
  1322. . "B0424394424300F8DEDFEFFFF83842410010000018BBC24000"
  1323. . "100008B442444017C243C3B8424100100000F8D9CFEFFFFE97"
  1324. . "CFBFFFF0F1F0048634424208B5424400B1424488BBC2460010"
  1325. . "0008D48013B8C24680100008914870F8D56FBFFFF830424018"
  1326. . "3C504894C24208B0424394424300F8D82FEFFFFEB93448B5C2"
  1327. . "428448B84242001000031DB8B84241801000031F6448B94241"
  1328. . "80100004183C30141C1E3074585C08D2C85000000000F8E8CF"
  1329. . "9FFFF4585D27E57488B8C24F80000004C63CE4C038C2430010"
  1330. . "0004863C74531C0488D4C01020FB6110FB641FF440FB661FE6"
  1331. . "BC04B6BD22601C24489E0C1E0044429E001D04139C3430F970"
  1332. . "4014983C0014883C1044539C27FCC01EF4401D683C3014401E"
  1333. . "F399C24200100007595E91CF9FFFF8B8C24200100008B84241"
  1334. . "801000031DB31F6448B8C241801000085C98D2C85000000007"
  1335. . "E7D4585C97E694C63C6488B8C24F80000004863C74D89C24C0"
  1336. . "38424300100004C0394242801000031D2488D4C0102440FB61"
  1337. . "90FB641FF4883C104440FB661FA6BC04B456BDB264101C3448"
  1338. . "9E0C1E0044429E04401D8C1F8074188041241C60410004883C"
  1339. . "2014139D17FC401EF4401CE83C3014401EF399C24200100007"
  1340. . "58383BC2420010000020F8E6CF8FFFF4863B424180100008B9"
  1341. . "C24180100008BBC2420010000488D5601448D67FFBF0100000"
  1342. . "04889D0480394243001000048038424280100004889D58D53F"
  1343. . "D4C8D6A0183BC241801000002488D1C067E7E4989C04D8D5C0"
  1344. . "5004989D94929F04889E90FB610440FB650FF035424284439D"
  1345. . "27C44440FB650014439D27C3A450FB6104439D27C31450FB61"
  1346. . "14439D27C28450FB650FF4439D27C1E450FB650014439D27C1"
  1347. . "4450FB651FF4439D27C0A450FB651014439D27D03C60101488"
  1348. . "3C0014983C1014883C1014983C0014C39D8759383C7014801F"
  1349. . "54889D84139FC0F8562FFFFFFE989F7FFFF31C9E9FAF8FFFF9"
  1350. . "0909090909090909090909090"
  1351. MCode(MyFunc, A_PtrSize=8 ? x64:x32)
  1352. }
  1353. return, DllCall(&MyFunc, "int",mode, "uint",color
  1354. , "uint",n, "int",offsetX, "int",offsetY, Ptr,Scan0
  1355. , "int",Stride, "int",sx, "int",sy, "int",sw, "int",sh
  1356. , Ptr,&gs, Ptr,&ss, "AStr",text, Ptr,&s1, Ptr,&s0
  1357. , Ptr,&input, "int",num, Ptr,&allpos, "int",allpos_max)
  1358. }
  1359.  
  1360. xywh2xywh(x1,y1,w1,h1,ByRef x,ByRef y,ByRef w,ByRef h)
  1361. {
  1362. SysGet, zx, 76
  1363. SysGet, zy, 77
  1364. SysGet, zw, 78
  1365. SysGet, zh, 79
  1366. left:=x1, right:=x1+w1-1, up:=y1, down:=y1+h1-1
  1367. left:=left<zx ? zx:left, right:=right>zx+zw-1 ? zx+zw-1:right
  1368. up:=up<zy ? zy:up, down:=down>zy+zh-1 ? zy+zh-1:down
  1369. x:=left, y:=up, w:=right-left+1, h:=down-up+1
  1370. }
  1371.  
  1372. GetBitsFromScreen(x, y, w, h, ByRef Scan0, ByRef Stride
  1373. , ScreenShot=1, ByRef zx="", ByRef zy="", bpp=32)
  1374. {
  1375. static bits, oldx, oldy, oldw, oldh
  1376. static Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr "*"
  1377. if (ScreenShot or x<oldx or y<oldy
  1378. or x+w>oldx+oldw or y+h>oldy+oldh)
  1379. {
  1380. oldx:=x, oldy:=y, oldw:=w, oldh:=h, ScreenShot:=1
  1381. VarSetCapacity(bits, w*h*4)
  1382. }
  1383. Scan0:=&bits, Stride:=((oldw*bpp+31)//32)*4, zx:=oldx, zy:=oldy
  1384. if (!ScreenShot or w<1 or h<1)
  1385. return
  1386. win:=DllCall("GetDesktopWindow", Ptr)
  1387. hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
  1388. mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
  1389. ;-------------------------
  1390. VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
  1391. NumPut(w, bi, 4, "int"), NumPut(-h, bi, 8, "int")
  1392. NumPut(1, bi, 12, "short"), NumPut(bpp, bi, 14, "short")
  1393. ;-------------------------
  1394. if hBM:=DllCall("CreateDIBSection", Ptr,mDC, Ptr,&bi
  1395. , "int",0, PtrP,ppvBits, Ptr,0, "int",0, Ptr)
  1396. {
  1397. oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
  1398. DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",w, "int",h
  1399. , Ptr,hDC, "int",x, "int",y, "uint",0x00CC0020|0x40000000)
  1400. DllCall("RtlMoveMemory", Ptr,Scan0, Ptr,ppvBits, Ptr,Stride*h)
  1401. DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
  1402. DllCall("DeleteObject", Ptr,hBM)
  1403. }
  1404. DllCall("DeleteDC", Ptr,mDC)
  1405. DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
  1406. }
  1407.  
  1408. MCode(ByRef code, hex)
  1409. {
  1410. bch:=A_BatchLines
  1411. SetBatchLines, -1
  1412. VarSetCapacity(code, len:=StrLen(hex)//2)
  1413. lls:=A_ListLines=0 ? "Off" : "On"
  1414. ListLines, Off
  1415. Loop, % len
  1416. NumPut("0x" SubStr(hex,2*A_Index-1,2),code,A_Index-1,"uchar")
  1417. ListLines, %lls%
  1418. Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr . "*"
  1419. DllCall("VirtualProtect",Ptr,&code, Ptr,len,"uint",0x40,PtrP,0)
  1420. SetBatchLines, %bch%
  1421. }
  1422.  
  1423. base64tobit(s)
  1424. {
  1425. Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1426. . "abcdefghijklmnopqrstuvwxyz"
  1427. SetFormat, IntegerFast, d
  1428. StringCaseSense, On
  1429. lls:=A_ListLines=0 ? "Off" : "On"
  1430. ListLines, Off
  1431. Loop, Parse, Chars
  1432. {
  1433. i:=A_Index-1, v:=(i>>5&1) . (i>>4&1)
  1434. . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  1435. s:=StrReplace(s,A_LoopField,v)
  1436. }
  1437. ListLines, %lls%
  1438. StringCaseSense, Off
  1439. s:=SubStr(s,1,InStr(s,"1",0,0)-1)
  1440. s:=RegExReplace(s,"[^01]+")
  1441. return, s
  1442. }
  1443.  
  1444. bit2base64(s)
  1445. {
  1446. s:=RegExReplace(s,"[^01]+")
  1447. s.=SubStr("100000",1,6-Mod(StrLen(s),6))
  1448. s:=RegExReplace(s,".{6}","|$0")
  1449. Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1450. . "abcdefghijklmnopqrstuvwxyz"
  1451. SetFormat, IntegerFast, d
  1452. lls:=A_ListLines=0 ? "Off" : "On"
  1453. ListLines, Off
  1454. Loop, Parse, Chars
  1455. {
  1456. i:=A_Index-1, v:="|" . (i>>5&1) . (i>>4&1)
  1457. . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  1458. s:=StrReplace(s,v,A_LoopField)
  1459. }
  1460. ListLines, %lls%
  1461. return, s
  1462. }
  1463.  
  1464. ASCII(s)
  1465. {
  1466. if RegExMatch(s,"\$(\d+)\.([\w+/]+)",r)
  1467. {
  1468. s:=RegExReplace(base64tobit(r2),".{" r1 "}","$0`n")
  1469. s:=StrReplace(StrReplace(s,"0","_"),"1","0")
  1470. }
  1471. else s=
  1472. return, s
  1473. }
  1474.  
  1475. ; You can put the text library at the beginning of the script,
  1476. ; and Use Pic(Text,1) to add the text library to Pic()'s Lib,
  1477. ; Use Pic("comment1|comment2|...") to get text images from Lib
  1478.  
  1479. Pic(comments, add_to_Lib=0)
  1480. {
  1481. static Lib:=[]
  1482. if (add_to_Lib)
  1483. {
  1484. re:="<([^>]*)>[^$]+\$\d+\.[\w+/]+"
  1485. Loop, Parse, comments, |
  1486. if RegExMatch(A_LoopField,re,r)
  1487. Lib[Trim(r1)]:=r
  1488. Lib[""]:=""
  1489. }
  1490. else
  1491. {
  1492. Text:=""
  1493. Loop, Parse, comments, |
  1494. Text.="|" . Lib[Trim(A_LoopField)]
  1495. return, Text
  1496. }
  1497. }
  1498.  
  1499. PicN(Number)
  1500. {
  1501. return, Pic( RegExReplace(Number, ".", "|$0") )
  1502. }
  1503.  
  1504. ; Use PicX(Text) to automatically cut into multiple characters
  1505. ; Can't be used in ColorPos mode, because it can cause position errors
  1506.  
  1507. PicX(Text)
  1508. {
  1509. if !RegExMatch(Text,"\|([^$]+)\$(\d+)\.([\w+/]+)",r)
  1510. return, Text
  1511. w:=r2, v:=base64tobit(r3), Text:=""
  1512. c:=StrLen(StrReplace(v,"0"))<=StrLen(v)//2 ? "1":"0"
  1513. wz:=RegExReplace(v,".{" w "}","$0`n")
  1514. SetFormat, IntegerFast, d
  1515. While InStr(wz,c) {
  1516. While !(wz~="m`n)^" c)
  1517. wz:=RegExReplace(wz,"m`n)^.")
  1518. i:=0
  1519. While (wz~="m`n)^.{" i "}" c)
  1520. i++
  1521. v:=RegExReplace(wz,"m`n)^(.{" i "}).*","$1")
  1522. wz:=RegExReplace(wz,"m`n)^.{" i "}")
  1523. if v!=
  1524. Text.="|" r1 "$" i "." bit2base64(v)
  1525. }
  1526. return, Text
  1527. }
  1528.  
  1529. ; Screenshot and retained as the last screenshot.
  1530.  
  1531. ScreenShot()
  1532. {
  1533. n:=150000
  1534. xywh2xywh(-n,-n,2*n+1,2*n+1,x,y,w,h)
  1535. GetBitsFromScreen(x,y,w,h,Scan0,Stride,1)
  1536. }
  1537.  
  1538. FindTextOCR(nX, nY, nW, nH, err1, err0, Text, Interval=20)
  1539. {
  1540. OCR:="", RightX:=nX+nW-1, ScreenShot()
  1541. While (ok:=FindText(nX, nY, nW, nH, err1, err0, Text, 0))
  1542. {
  1543. For k,v in ok
  1544. {
  1545. ; X is the X coordinates of the upper left corner
  1546. ; and W is the width of the image have been found
  1547. x:=v.1, y:=v.2, w:=v.3, h:=v.4, comment:=v.5
  1548. ; We need the leftmost X coordinates
  1549. if (A_Index=1 or x<LeftX)
  1550. LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  1551. else if (x=LeftX)
  1552. {
  1553. Loop, 100
  1554. {
  1555. err:=A_Index/100
  1556. if FindText(x, y, w, h, err, err, Text, 0)
  1557. {
  1558. LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  1559. Break
  1560. }
  1561. if FindText(LeftX, LeftY, LeftW, LeftH, err, err, Text, 0)
  1562. Break
  1563. }
  1564. }
  1565. }
  1566. ; If the interval exceeds the set value, add "*" to the result
  1567. OCR.=(A_Index>1 and LeftX-nX-1>Interval ? "*":"") . LeftOCR
  1568. ; Update nX and nW for next search
  1569. nX:=LeftX+LeftW-1, nW:=RightX-nX+1
  1570. }
  1571. return, OCR
  1572. }
  1573.  
  1574. ; Reordering the objects returned from left to right,
  1575. ; from top to bottom, ignore slight height difference
  1576.  
  1577. SortOK(ok, dy=10) {
  1578. if !IsObject(ok)
  1579. return, ok
  1580. SetFormat, IntegerFast, d
  1581. For k,v in ok
  1582. {
  1583. x:=v.1+v.3//2, y:=v.2+v.4//2
  1584. y:=A_Index>1 and Abs(y-lasty)<dy ? lasty : y, lasty:=y
  1585. n:=(y*150000+x) "." k, s:=A_Index=1 ? n : s "-" n
  1586. }
  1587. Sort, s, N D-
  1588. ok2:=[]
  1589. Loop, Parse, s, -
  1590. ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  1591. return, ok2
  1592. }
  1593.  
  1594. ; Reordering according to the nearest distance
  1595.  
  1596. SortOK2(ok, px, py) {
  1597. if !IsObject(ok)
  1598. return, ok
  1599. SetFormat, IntegerFast, d
  1600. For k,v in ok
  1601. {
  1602. x:=v.1+v.3//2, y:=v.2+v.4//2
  1603. n:=((x-px)**2+(y-py)**2) "." k
  1604. s:=A_Index=1 ? n : s "-" n
  1605. }
  1606. Sort, s, N D-
  1607. ok2:=[]
  1608. Loop, Parse, s, -
  1609. ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  1610. return, ok2
  1611. }
  1612.  
  1613. ; Prompt mouse position in remote assistance
  1614.  
  1615. MouseTip(x="", y="") {
  1616. if (x="")
  1617. {
  1618. VarSetCapacity(pt,16,0), DllCall("GetCursorPos","ptr",&pt)
  1619. x:=NumGet(pt,0,"uint"), y:=NumGet(pt,4,"uint")
  1620. }
  1621. x:=Round(x-10), y:=Round(y-10), w:=h:=2*10+1
  1622. ;-------------------------
  1623. Gui, _MouseTip_: +AlwaysOnTop -Caption +ToolWindow +Hwndmyid +E0x08000000
  1624. Gui, _MouseTip_: Show, Hide w%w% h%h%
  1625. ;-------------------------
  1626. dhw:=A_DetectHiddenWindows
  1627. DetectHiddenWindows, On
  1628. d:=4, i:=w-d, j:=h-d
  1629. s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
  1630. s=%s% %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
  1631. WinSet, Region, %s%, ahk_id %myid%
  1632. DetectHiddenWindows, %dhw%
  1633. ;-------------------------
  1634. Gui, _MouseTip_: Show, NA x%x% y%y%
  1635. Loop, 4 {
  1636. Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
  1637. Sleep, 500
  1638. }
  1639. Gui, _MouseTip_: Destroy
  1640. }
  1641.  
  1642.  
  1643. /***** C source code of machine code *****
  1644.  
  1645. int __attribute__((__stdcall__)) PicFind(
  1646. int mode, unsigned int c, unsigned int n
  1647. , int offsetX, int offsetY, unsigned char * Bmp
  1648. , int Stride, int sx, int sy, int sw, int sh
  1649. , unsigned char * gs, char * ss, char * text
  1650. , int * s1, int * s0, int * input, int num
  1651. , unsigned int * allpos, int allpos_max)
  1652. {
  1653. int o, i, j, x, y, r, g, b, rr, gg, bb, max, e1, e0, ok;
  1654. int o1, x1, y1, w1, h1, sx1, sy1, len1, len0, err1, err0;
  1655. int o2, x2, y2, w2, h2, sx2, sy2, len21, len20, err21, err20;
  1656. int r_min, r_max, g_min, g_max, b_min, b_max;
  1657. //----------------------
  1658. ok=0; w1=input[1]; h1=input[2];
  1659. len1=input[3]; len0=input[4];
  1660. err1=input[5]; err0=input[6];
  1661. max=len1>len0 ? len1 : len0;
  1662. //----------------------
  1663. // Generate Lookup Table
  1664. for (j=0; j<num; j+=7)
  1665. {
  1666. o=o1=o2=input[j]; w2=input[j+1]; h2=input[j+2];
  1667. for (y=0; y<h2; y++)
  1668. {
  1669. for (x=0; x<w2; x++)
  1670. {
  1671. i=(mode==3) ? y*Stride+x*4 : y*sw+x;
  1672. if (text[o++]=='1')
  1673. s1[o1++]=i;
  1674. else
  1675. s0[o2++]=i;
  1676. }
  1677. }
  1678. }
  1679. // Color Position Mode
  1680. // This mode is not support combination lookup
  1681. // only used to recognize multicolored Verification Code
  1682. if (mode==3)
  1683. {
  1684. sx1=sx+sw-w1; sy1=sy+sh-h1;
  1685. for (y=sy; y<=sy1; y++)
  1686. {
  1687. for (x=sx; x<=sx1; x++)
  1688. {
  1689. o=y*Stride+x*4; e1=err1; e0=err0;
  1690. j=o+c; rr=Bmp[2+j]; gg=Bmp[1+j]; bb=Bmp[j];
  1691. for (i=0; i<max; i++)
  1692. {
  1693. if (i<len1)
  1694. {
  1695. j=o+s1[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  1696. if (3*r*r+4*g*g+2*b*b>n && (--e1)<0)
  1697. goto NoMatch3;
  1698. }
  1699. if (i<len0)
  1700. {
  1701. j=o+s0[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  1702. if (3*r*r+4*g*g+2*b*b<=n && (--e0)<0)
  1703. goto NoMatch3;
  1704. }
  1705. }
  1706. allpos[ok++]=y<<16|x;
  1707. if (ok>=allpos_max)
  1708. goto Return1;
  1709. NoMatch3:
  1710. continue;
  1711. }
  1712. }
  1713. goto Return1;
  1714. }
  1715. // Generate Two Value Image
  1716. o=sy*Stride+sx*4; j=Stride-4*sw; i=0;
  1717. if (mode==0) // Color Mode
  1718. {
  1719. rr=(c>>16)&0xFF; gg=(c>>8)&0xFF; bb=c&0xFF;
  1720. for (y=0; y<sh; y++, o+=j)
  1721. for (x=0; x<sw; x++, o+=4, i++)
  1722. {
  1723. r=Bmp[2+o]-rr; g=Bmp[1+o]-gg; b=Bmp[o]-bb;
  1724. ss[i]=(3*r*r+4*g*g+2*b*b<=n) ? 1:0;
  1725. }
  1726. }
  1727. else if (mode==1) // Gray Threshold Mode
  1728. {
  1729. c=(c+1)*128;
  1730. for (y=0; y<sh; y++, o+=j)
  1731. for (x=0; x<sw; x++, o+=4, i++)
  1732. ss[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15<c) ? 1:0;
  1733. }
  1734. else if (mode==2) // Gray Difference Mode
  1735. {
  1736. for (y=0; y<sh; y++, o+=j)
  1737. {
  1738. for (x=0; x<sw; x++, o+=4, i++)
  1739. {
  1740. gs[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15)>>7;
  1741. ss[i]=0;
  1742. }
  1743. }
  1744. sx1=sw-2; sy1=sh-2;
  1745. for (y=1; y<=sy1; y++)
  1746. for (x=1; x<=sx1; x++)
  1747. {
  1748. i=y*sw+x; j=gs[i]+c;
  1749. if ( gs[i-1]>j || gs[i+1]>j
  1750. || gs[i-sw]>j || gs[i+sw]>j
  1751. || gs[i-sw-1]>j || gs[i-sw+1]>j
  1752. || gs[i+sw-1]>j || gs[i+sw+1]>j )
  1753. ss[i]=1;
  1754. }
  1755. }
  1756. else // (mode==4) Color Difference Mode
  1757. {
  1758. r=(c>>16)&0xFF; g=(c>>8)&0xFF; b=c&0xFF;
  1759. rr=(n>>16)&0xFF; gg=(n>>8)&0xFF; bb=n&0xFF;
  1760. r_min=r-rr; g_min=g-gg; b_min=b-bb;
  1761. r_max=r+rr; g_max=g+gg; b_max=b+bb;
  1762. for (y=0; y<sh; y++, o+=j)
  1763. for (x=0; x<sw; x++, o+=4, i++)
  1764. {
  1765. r=Bmp[2+o]; g=Bmp[1+o]; b=Bmp[o];
  1766. ss[i]=(r>=r_min && r<=r_max
  1767. && g>=g_min && g<=g_max
  1768. && b>=b_min && b<=b_max) ? 1:0;
  1769. }
  1770. }
  1771. // Start Lookup
  1772. sx1=sw-w1; sy1=sh-h1;
  1773. for (y=0; y<=sy1; y++)
  1774. {
  1775. for (x=0; x<=sx1; x++)
  1776. {
  1777. o=y*sw+x; e1=err1; e0=err0;
  1778. if (e0==len0)
  1779. {
  1780. for (i=0; i<len1; i++)
  1781. if (ss[o+s1[i]]!=1 && (--e1)<0)
  1782. goto NoMatch1;
  1783. }
  1784. else
  1785. {
  1786. for (i=0; i<max; i++)
  1787. {
  1788. if (i<len1 && ss[o+s1[i]]!=1 && (--e1)<0)
  1789. goto NoMatch1;
  1790. if (i<len0 && ss[o+s0[i]]!=0 && (--e0)<0)
  1791. goto NoMatch1;
  1792. }
  1793. }
  1794. //------------------
  1795. if (num>7)
  1796. {
  1797. x1=x+w1-1; y1=y-offsetY; if (y1<0) y1=0;
  1798. for (j=7; j<num; j+=7)
  1799. {
  1800. o2=input[j]; w2=input[j+1]; h2=input[j+2];
  1801. len21=input[j+3]; len20=input[j+4];
  1802. err21=input[j+5]; err20=input[j+6];
  1803. sx2=sw-w2; i=x1+offsetX; if (i<sx2) sx2=i;
  1804. sy2=sh-h2; i=y+offsetY; if (i<sy2) sy2=i;
  1805. for (x2=x1; x2<=sx2; x2++)
  1806. {
  1807. for (y2=y1; y2<=sy2; y2++)
  1808. {
  1809. o1=y2*sw+x2; e1=err21; e0=err20;
  1810. for (i=0; i<len21; i++)
  1811. {
  1812. if (ss[o1+s1[o2+i]]!=1 && (--e1)<0)
  1813. goto NoMatch2;
  1814. }
  1815. if (e0!=len20)
  1816. {
  1817. for (i=0; i<len20; i++)
  1818. if (ss[o1+s0[o2+i]]!=0 && (--e0)<0)
  1819. goto NoMatch2;
  1820. }
  1821. goto MatchOK;
  1822. NoMatch2:
  1823. continue;
  1824. }
  1825. }
  1826. goto NoMatch1;
  1827. MatchOK:
  1828. x1=x2+w2-1;
  1829. }
  1830. }
  1831. //------------------
  1832. allpos[ok++]=(sy+y)<<16|(sx+x);
  1833. if (ok>=allpos_max)
  1834. goto Return1;
  1835. // Clear the image that has been found
  1836. for (i=0; i<len1; i++)
  1837. ss[o+s1[i]]=0;
  1838. NoMatch1:
  1839. continue;
  1840. }
  1841. }
  1842. Return1:
  1843. return ok;
  1844. }
  1845.  
  1846. */
  1847.  
  1848. ;================= The End =================
  1849.  
  1850. ;
Add Comment
Please, Sign In to add comment