-
Notifications
You must be signed in to change notification settings - Fork 72
/
FindTextGui.ahk
2458 lines (2420 loc) · 78.8 KB
/
FindTextGui.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;/*
;===========================================
; FindText - Capture screen image into text and then find it
; https://autohotkey.com/boards/viewtopic.php?f=6&t=17834
;
; Author : FeiYue
; Version : 7.5
; Date : 2020-04-13
;
; Usage:
; 1. Capture the image to text string.
; 2. Test find the text string on full Screen.
; 3. When test is successful, you may copy the code
; and paste it into your own script.
; Note: Copy the "FindText()" function and the following
; functions and paste it into your own script Just once.
; 4. The more recommended way is to save the script as
; "FindText.ahk" and copy it to the "Lib" subdirectory
; of AHK program, instead of copying the "FindText()"
; function and the following functions, add a line to
; the beginning of your script: #Include <FindText>
;
; Note:
; After upgrading to v7.0, the search scope using
; the upper left corner coordinates (X1, Y1)
; and lower right corner coordinates (X2, Y2), similar to ImageSearch.
; This makes it easier for novices to understand and use.
;
;===========================================
; Introduction of function parameters:
;
; returnArray := FindText(
; X1 --> the search scope's upper left corner X coordinates
; , Y1 --> the search scope's upper left corner Y coordinates
; , X2 --> the search scope's lower right corner X coordinates
; , Y2 --> the search scope's lower right corner Y coordinates
; , err1 --> Fault tolerance percentage of text (0.1=10%)
; , err0 --> Fault tolerance percentage of background (0.1=10%)
; , Text --> can be a lot of text parsed into images, separated by "|"
; , ScreenShot --> if the value is 0, the last screenshot will be used
; , FindAll --> if the value is 0, Just find one result and return
; , JoinText --> if the value is 1, Join all Text for combination lookup
; , offsetX --> Set the max text offset for combination lookup
; , offsetY --> Set the max text offset for combination lookup
; )
;
; The function returns a second-order array containing
; all lookup results, Any result is an associative array
; {1:X, 2:Y, 3:W, 4:H, x:X+W//2, y:Y+H//2, id:Comment}
; if no image is found, the function returns 0.
;
; If the return variable is set to "ok", ok.1 is the first result found.
; Where ok.1.1 is the X coordinate of the upper left corner of the found image,
; and ok.1.2 is the Y coordinate of the upper left corner of the found image,
; ok.1.3 is the width of the found image, and ok.1.4 is the height of the found image,
; ok.1.x <==> ok.1.1+ok.1.3//2 ( is the Center X coordinate of the found image ),
; ok.1.y <==> ok.1.2+ok.1.4//2 ( is the Center Y coordinate of the found image ),
; ok.1.id is the comment text, which is included in the <> of its parameter.
; ok.1.x can also be written as ok[1].x, which supports variables. (eg: ok[A_Index].x)
;
; All coordinates are relative to Screen, colors are in RGB format,
; and combination lookup must use uniform color mode
;===========================================
;*/
if (!A_IsCompiled && A_LineFile=A_ScriptFullPath)
FindText_Gui("Show")
FindText_Gui(cmd, arg1:="") {
local
static
local lls, bch, cri
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
static init:=0
if (!init)
{
ListLines, %lls%
static FindText_FuncBind1:=Func("FindText_Gui").Bind("Show")
bch:=A_BatchLines, cri:=A_IsCritical
Critical
init:=1, ww:=35, hh:=12, WindowColor:="0xDDEEFF"
#NoEnv
Menu, Tray, Add
Menu, Tray, Add, FindText, %FindText_FuncBind1%
if (!A_IsCompiled and A_LineFile=A_ScriptFullPath)
{
Menu, Tray, Default, FindText
Menu, Tray, Click, 1
Menu, Tray, Icon, Shell32.dll, 23
}
FindText_Gui("MakeCaptureWindow")
FindText_Gui("MakeSubPicWindow")
FindText_Gui("MakeMainWindow")
OnMessage(0x100, Func("FindText_Gui").Bind("EditEvents1")) ; WM_KEYDOWN
OnMessage(0x201, Func("FindText_Gui").Bind("EditEvents2")) ; WM_LBUTTONDOWN
OnMessage(0x200, Func("FindText_Gui").Bind("ShowToolTip")) ; WM_MOUSEMOVE
Critical, %cri%
SetBatchLines, %bch%
}
if (cmd="Show")
{
ListLines, %lls%
Gui, FindText_Main: Show, Center
GuiControl, FindText_Main: Focus, scr
return
;---------------------
FindText_Run:
Critical
FindText_Gui(Trim(A_GuiControl))
FindText_RButton_Off:
return
}
if (cmd="MakeCaptureWindow")
{
ListLines, %lls%
Gui, FindText_Capture: New
Gui, +AlwaysOnTop -DPIScale +HwndCapture_ID
Gui, Margin, 15, 15
Gui, Color, %WindowColor%
Gui, Font, s12, Verdana
Gui, Add, Text, xm w855 h315 +HwndhPic
Gui, Add, Slider, ym h315 vMySlider2 gFindText_Run
+Center Page20 Line20 NoTicks AltSubmit +Vertical
Gui, Add, Slider, xm w855 vMySlider1 gFindText_Run
+Center Page20 Line20 NoTicks AltSubmit
GuiControlGet, p, Pos, %hPic%
PicW:=Round(pW), PicH:=Round(pH), MySlider1:=MySlider2:=0
Gui, Add, Button, xm+125 w50 vRepU gFindText_Run, -U
Gui, Add, Button, x+0 wp vCutU gFindText_Run, U
Gui, Add, Button, x+0 wp vCutU3 gFindText_Run, U3
;--------------
Gui, Add, Text, x+50 yp+3 Section, Gray
Gui, Add, Edit, x+3 yp-3 w60 vSelGray ReadOnly
Gui, Add, Text, x+15 ys, Color
Gui, Add, Edit, x+3 yp-3 w120 vSelColor ReadOnly
Gui, Add, Text, x+15 ys, R
Gui, Add, Edit, x+3 yp-3 w60 vSelR ReadOnly
Gui, Add, Text, x+5 ys, G
Gui, Add, Edit, x+3 yp-3 w60 vSelG ReadOnly
Gui, Add, Text, x+5 ys, B
Gui, Add, Edit, x+3 yp-3 w60 vSelB ReadOnly
;--------------
Gui, Add, Button, xm w50 vRepL gFindText_Run, -L
Gui, Add, Button, x+0 wp vCutL gFindText_Run, L
Gui, Add, Button, x+0 wp vCutL3 gFindText_Run, L3
Gui, Add, Button, x+15 w70 vAuto gFindText_Run, Auto
Gui, Add, Button, x+15 w50 vRepR gFindText_Run, -R
Gui, Add, Button, x+0 wp vCutR gFindText_Run, R
Gui, Add, Button, x+0 wp vCutR3 gFindText_Run Section, R3
Gui, Add, Button, xm+125 w50 vRepD gFindText_Run, -D
Gui, Add, Button, x+0 wp vCutD gFindText_Run, D
Gui, Add, Button, x+0 wp vCutD3 gFindText_Run, D3
;--------------
Gui, Add, Tab3, ys-8 -Wrap, Gray|GrayDiff|Color|ColorPos|ColorDiff
Gui, Tab, 1
Gui, Add, Text, x+15 y+15, Gray Threshold
Gui, Add, Edit, x+15 w100 vThreshold
Gui, Add, Button, x+15 yp-3 vGray2Two gFindText_Run, Gray2Two
Gui, Tab, 2
Gui, Add, Text, x+15 y+15, Gray Difference
Gui, Add, Edit, x+15 w100 vGrayDiff, 50
Gui, Add, Button, x+15 yp-3 vGrayDiff2Two gFindText_Run, GrayDiff2Two
Gui, Tab, 3
Gui, Add, Text, x+15 y+15, Similarity 0
Gui, Add, Slider, x+0 w100 vSimilar1 gFindText_Run
+Center Page1 NoTicks ToolTip, 100
Gui, Add, Text, x+0, 100
Gui, Add, Button, x+15 yp-3 vColor2Two gFindText_Run, Color2Two
Gui, Tab, 4
Gui, Add, Text, x+15 y+15, Similarity 0
Gui, Add, Slider, x+0 w100 vSimilar2 gFindText_Run
+Center Page1 NoTicks ToolTip, 100
Gui, Add, Text, x+0, 100
Gui, Add, Button, x+15 yp-3 vColorPos2Two gFindText_Run, ColorPos2Two
Gui, Tab, 5
Gui, Add, Text, x+10 y+15, R
Gui, Add, Edit, x+2 w70 vDiffR Limit3
Gui, Add, UpDown, vdR Range0-255
Gui, Add, Text, x+5, G
Gui, Add, Edit, x+2 w70 vDiffG Limit3
Gui, Add, UpDown, vdG Range0-255
Gui, Add, Text, x+5, B
Gui, Add, Edit, x+2 w70 vDiffB Limit3
Gui, Add, UpDown, vdB Range0-255
Gui, Add, Button, x+5 yp-3 vColorDiff2Two gFindText_Run, ColorDiff2Two
Gui, Tab
;--------------
Gui, Add, Button, xm vReset gFindText_Run, Reset
Gui, Add, Checkbox, x+15 yp+5 vModify gFindText_Run, Modify
Gui, Add, Text, x+30, Comment
Gui, Add, Edit, x+5 yp-2 w150 vComment
Gui, Add, Button, x+30 yp-3 vSplitAdd gFindText_Run, SplitAdd
Gui, Add, Button, x+10 vAllAdd gFindText_Run, AllAdd
Gui, Add, Button, x+10 w80 vButtonOK gFindText_Run, OK
Gui, Add, Button, x+10 wp vClose gCancel, Close
Gui, Add, Button, xm vBind1 gFindText_Run, BindWindow
Gui, Add, Button, x+15 vBind2 gFindText_Run, BindWindow+
Gui, Show, Hide, Capture Image To Text
return
}
if (cmd="MakeSubPicWindow")
{
ListLines, %lls%
Gui, FindText_SubPic: New
Gui, +AlwaysOnTop -Caption +ToolWindow -DPIScale +Parent%hPic%
Gui, Margin, 0, 0
Gui, Color, %WindowColor%
Gui, -Theme
nW:=2*ww+1, nH:=2*hh+1, C_:=[], w:=11
Loop, % nW*(nH+1)
{
i:=A_Index, j:=i=1 ? "x0 y0" : Mod(i,nW)=1 ? "x0 y+1" : "x+1"
j.=i>nW*nH ? " cRed BackgroundFFFFAA" : ""
Gui, Add, Progress, w%w% h%w% %j% +Hwndid
Control, ExStyle, -0x20000,, ahk_id %id%
C_[i]:=id
}
Gui, +Theme
GuiControlGet, p, Pos, %id%
SubPicW:=Round(pX+pW), SubPicH:=Round(pY+pH)
Gui, Show, NA x0 y0 w%SubPicW% h%SubPicH%, SubPic
i:=(SubPicW>PicW), j:=(SubPicH>PicH)
Gui, FindText_Capture: Default
GuiControl, Enable%i%, MySlider1
GuiControl, Enable%j%, MySlider2
GuiControl,, MySlider1, % MySlider1:=0
GuiControl,, MySlider2, % MySlider2:=0
return
}
if (cmd="MakeMainWindow")
{
ListLines, %lls%
Gui, FindText_Main: New
Gui, +AlwaysOnTop -DPIScale
Gui, Margin, 15, 15
Gui, Color, %WindowColor%
Gui, Font, s12 cBlack, Verdana
Gui, Add, Text, xm, Hotkey
Gui, Add, Edit, x+5 w200 vNowHotkey ReadOnly
Gui, Add, Hotkey, x+5 w200 vSetHotkey1
Gui, Add, DDL, x+5 w180 vSetHotkey2
, % "||F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|MButton"
. "|ScrollLock|CapsLock|Ins|Esc|BS|Del|Tab|Home|End|PgUp|PgDn"
. "|NumpadDot|NumpadSub|NumpadAdd|NumpadDiv|NumpadMult"
Gui, Add, GroupBox, xm y+0 w280 h55 vMyGroup
Gui, Add, Text, xp+15 yp+20 Section, % "Width: "
Gui, Add, Text, x+0 w60, %ww%
Gui, Add, UpDown, vMyww Range1-50, %ww%
Gui, Add, Text, x+15 ys, % "Height: "
Gui, Add, Text, x+0 w60, %hh%
Gui, Add, UpDown, vMyhh Range1-40, %hh%
GuiControlGet, p, Pos, Myhh
GuiControl, Move, MyGroup, % "w" (pX+pW) " h" (pH+30)
x:=pX+pW+15*2
Gui, Add, Button, x%x% ys-8 w150 vApply gFindText_Run, Apply
Gui, Add, Checkbox, x+15 ys Checked vAddFunc, Add FindText()
Gui, Font, s6 bold, Verdana
Gui, Add, Edit, xm w720 r20 vMyPic -Wrap
Gui, Font, s12 norm, Verdana
Gui, Add, Button, w240 vCapture gFindText_Run, Capture
Gui, Add, Button, x+0 wp vTest gFindText_Run, Test
Gui, Add, Button, x+0 wp vCopy gFindText_Run Section, Copy
Gui, Add, Button, xm y+0 wp vCaptureS gFindText_Run, CaptureS
Gui, Add, Button, x+0 wp vGetRange gFindText_Run, GetRange
Gui, Add, Button, x+0 wp vTestClip gFindText_Run, TestClipboard
Gui, Font, s12 cBlue, Verdana
Gui, Add, Edit, xm w720 h350 vscr Hwndhscr -Wrap HScroll
Gui, Show, Hide, Capture Image To Text And Find Text Tool
return
}
if (cmd="Capture"||cmd="CaptureS"||cmd="Capture_NoGui"||cmd="CaptureS_NoGui")
{
ListLines, %lls%
Critical
if !InStr(cmd,"NoGui")
{
Gui, FindText_Main: Default
Gui, +LastFound
WinMinimize
Gui, Hide
}
ShowScreenShot:=InStr(cmd,"CaptureS")
if (ShowScreenShot)
FindText_Gui("ShowScreenShot",1)
;----------------------
Hotkey, $*RButton, FindText_RButton_Off, On
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
CoordMode, Mouse
KeyWait, RButton
KeyWait, Ctrl
w:=ww, h:=hh, oldx:=oldy:=""
if InStr(cmd,"NoGui")
w:=20, h:=8
Loop
{
Sleep, 50
MouseGetPos, x, y, Bind_ID
if InStr(cmd,"NoGui")
{
w:=x<=1 ? w-1 : x>=A_ScreenWidth-2 ? w+1:w
h:=y<=1 ? h-1 : y>=A_ScreenHeight-2 ? h+1:h
}
FindText_Gui("Mini_Show")
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, % "The Capture Position : " x "," y
. "`nFirst click RButton to start capturing"
. "`nMove the mouse to avoid response"
. "`nSecond click RButton to end capture"
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
px:=x, py:=y, oldx:=oldy:=""
Loop
{
Sleep, 50
FindText_Gui("Mini_Show")
MouseGetPos, x1, y1
if (oldx=x1 and oldy=y1)
Continue
oldx:=x1, oldy:=y1
ToolTip, % "The Capture Position : " px "," py
. "`nFirst click RButton to start capturing"
. "`nMove the mouse to avoid response"
. "`nSecond click RButton to end capture"
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
ToolTip
FindText_Gui("Mini_Hide")
ListLines, %lls%
Hotkey, $*RButton, FindText_RButton_Off, Off
if (ShowScreenShot)
{
Gui, FindText_ScreenShot: +LastFoundExist
IfWinExist
{
WinGetPos, x, y
FindText_GetBitsFromScreen(0,0,0,0,0,x1,y1)
px-=Round(x-x1), py-=Round(y-y1)
}
FindText_Gui("ShowScreenShot",0)
}
if InStr(cmd,"NoGui")
return [px,py,w,h]
;-----------------------
FindText_Gui("getcors", !ShowScreenShot)
FindText_Gui("Reset")
Gui, FindText_Capture: Default
k:=nW*nH+1
Loop, % nW
GuiControl,, % C_[k++], 0
Loop, 6
GuiControl,, Edit%A_Index%
GuiControl,, Modify, % Modify:=0
GuiControl,, GrayDiff, 50
GuiControl, Focus, Gray2Two
GuiControl, +Default, Gray2Two
Gui, Show, Center
Event:=Result:=""
DetectHiddenWindows, Off
Critical, Off
WinWaitClose, ahk_id %Capture_ID%
Critical
Gui, FindText_Main: Default
;--------------------------------
if (cors.bind!="")
{
WinGetTitle, tt, ahk_id %Bind_ID%
WinGetClass, tc, ahk_id %Bind_ID%
tt:=Trim(SubStr(tt,1,30) (tc ? " ahk_class " tc:""))
tt:=StrReplace(RegExReplace(tt,"[;``]","``$0"),"""","""""")
Result:="`nSetTitleMatchMode, 2`nid:=WinExist(""" tt """)"
. "`nFindText_BindWindow(id" (cors.bind ? ",1":"")
. ") `; Unbind Window using FindText_BindWindow(0)`n`n" Result
}
if (Event="ButtonOK")
{
if (!A_IsCompiled)
{
FileRead, s, %A_LineFile%
s:=SubStr(s, s~="i)\n[;=]+ Copy The")
}
else s:=""
GuiControl,, scr, % Result "`n" s
GuiControl,, MyPic, % Trim(FindText_ASCII(Result),"`n")
Result:=s:=""
}
else if (Event="SplitAdd") or (Event="AllAdd")
{
GuiControlGet, s,, scr
i:=j:=0, r:="\|<[^>\n]*>[^$\n]+\$\d+\.[\w+/]+"
While j:=RegExMatch(s,r,"",j+1)
i:=InStr(s,"`n",0,j)
GuiControl,, scr, % SubStr(s,1,i) . Result . SubStr(s,i+1)
GuiControl,, MyPic, % Trim(FindText_ASCII(Result),"`n")
Result:=s:=""
}
;----------------------
Gui, Show
GuiControl, Focus, scr
return
}
if (cmd="ShowScreenShot")
{
ListLines, %lls%
local bits, zx, zy, zw, zh, bi, hDC, mDC, oBM, hBrush, oBrush
static hBM:="", Ptr:=A_PtrSize ? "UPtr" : "UInt"
Gui, FindText_ScreenShot: Destroy
if (hBM)
DllCall("DeleteObject",Ptr,hBM), hBM:=""
bits:=FindText_GetBitsFromScreen(0,0,0,0,0,zx,zy,zw,zh)
if (!arg1 or !bits.1 or zw<1 or zh<1)
return
;---------------------
VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
NumPut(zw, bi, 4, "int"), NumPut(-zh, bi, 8, "int")
NumPut(1, bi, 12, "short"), NumPut(bpp:=32, bi, 14, "short")
if (hBM:=DllCall("CreateDIBSection", Ptr,0, Ptr,&bi
, "int",0, Ptr "*",ppvBits:=0, Ptr,0, "int",0, Ptr))
DllCall("RtlMoveMemory",Ptr,ppvBits,Ptr,bits.1,Ptr,bits.2*zh)
;---------------------
win:=DllCall("GetDesktopWindow", Ptr)
hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
hBrush:=DllCall("CreateSolidBrush", "uint",0xFFFFFF, Ptr)
oBrush:=DllCall("SelectObject", Ptr,mDC, Ptr,hBrush, Ptr)
DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",zw, "int",zh
, Ptr,mDC, "int",0, "int",0, "uint",0xC000CA)
DllCall("SelectObject", Ptr,mDC, Ptr,oBrush)
DllCall("DeleteObject", Ptr,hBrush)
DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
DllCall("DeleteDC", Ptr,mDC)
DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
;---------------------
Gui, FindText_ScreenShot: +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x08000000
Gui, FindText_ScreenShot: Margin, 0, 0
Gui, FindText_ScreenShot: Add, Picture, x0 y0 w%zw% h%zh% +Hwndid +0xE
SendMessage, 0x172, 0, hBM,, ahk_id %id%
Gui, FindText_ScreenShot: Show, NA x%zx% y%zy% w%zw% h%zh%, Show ScreenShot
return
}
if (cmd="Mini_Show")
{
ListLines, %lls%
Gui, FindText_Mini_4: +LastFoundExist
IfWinNotExist
{
Loop, 4
{
i:=A_Index
Gui, FindText_Mini_%i%: +AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x08000000
Gui, FindText_Mini_%i%: Show, Hide, Mini
}
}
d:=2, w:=w<0 ? 0:w, h:=h<0 ? 0:h, r:=A_MSec<500 ? "Red":"Blue"
Loop, 4
{
i:=A_Index
x1:=Floor(i=3 ? x+w+1 : x-w-d)
y1:=Floor(i=4 ? y+h+1 : y-h-d)
w1:=Floor(i=1 or i=3 ? d : 2*(w+d)+1)
h1:=Floor(i=2 or i=4 ? d : 2*(h+d)+1)
Gui, FindText_Mini_%i%: Color, %r%
Gui, FindText_Mini_%i%: Show, NA x%x1% y%y1% w%w1% h%h1%
}
return
}
if (cmd="Mini_Hide")
{
ListLines, %lls%
Gui, FindText_Mini_4: +Hwndid
Loop, 4
Gui, FindText_Mini_%A_Index%: Destroy
WinWaitClose, ahk_id %id%,, 3
return
}
if (cmd="getcors")
{
ListLines, %lls%
FindText_xywh2xywh(px-ww,py-hh,2*ww+1,2*hh+1,x,y,w,h)
if (w<1 or h<1)
return
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
if (arg1)
FindText_ScreenShot()
cors:=[], k:=0
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
Loop, % 2*hh+1
{
j:=py-hh+A_Index-1
Loop, % 2*ww+1
i:=px-ww+A_Index-1, cors[++k]:=FindText_ScreenShot_GetColor(i,j)
}
ListLines, %lls%
cors.CutLeft:=Abs(px-ww-x)
cors.CutRight:=Abs(px+ww-(x+w-1))
cors.CutUp:=Abs(py-hh-y)
cors.CutDown:=Abs(py+hh-(y+h-1))
SetBatchLines, %bch%
return
}
if (cmd="GetRange")
{
ListLines, %lls%
Gui, FindText_Main: Hide
;---------------------
Gui, FindText_GetRange: New
Gui, +LastFound +AlWaysOnTop +ToolWindow -Caption -DPIScale +E0x08000000
Gui, Color, White
WinSet, Transparent, 10
FindText_GetBitsFromScreen(0,0,0,0,0,x,y,w,h)
Gui, Show, NA x%x% y%y% w%w% h%h%, GetRange
;---------------------
Hotkey, $*LButton, FindText_RButton_Off, On
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
CoordMode, Mouse
KeyWait, LButton
KeyWait, Ctrl
oldx:=oldy:=""
Loop
{
Sleep, 50
MouseGetPos, x, y
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, % "Please drag a range with the LButton"
. "`nCoordinates are copied to clipboard"
}
Until GetKeyState("LButton","P") or GetKeyState("Ctrl","P")
px:=x, py:=y, oldx:=oldy:=""
Loop
{
Sleep, 50
MouseGetPos, x, y
w:=Abs(px-x)//2, h:=Abs(py-y)//2, x:=(px+x)//2, y:=(py+y)//2
FindText_Gui("Mini_Show")
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
ToolTip, % "Please drag a range with the LButton"
. "`nCoordinates are copied to clipboard"
}
Until !(GetKeyState("LButton","P") or GetKeyState("Ctrl","P"))
ToolTip
FindText_Gui("Mini_Hide")
ListLines, %lls%
Hotkey, $*LButton, FindText_RButton_Off, Off
Gui, FindText_GetRange: Destroy
Clipboard:=p:=(x-w) ", " (y-h) ", " (x+w) ", " (y+h)
;---------------------
Gui, FindText_Main: Default
GuiControlGet, s,, scr
if RegExMatch(s, "i)(=\s*FindText\()([+\-\d\s]*,){4}", r)
{
s:=StrReplace(s, r, r1 . p ",", 0, 1)
GuiControl,, scr, %s%
}
Gui, Show
return
}
if (cmd="Test"||cmd="TestClip")
{
ListLines, %lls%
Gui, FindText_Main: Default
Gui, +LastFound
WinMinimize
Gui, Hide
DetectHiddenWindows, Off
WinWaitClose, % "ahk_id " WinExist()
Sleep, 100
;----------------------
if (cmd="Test")
GuiControlGet, s,, scr
else
s:=Clipboard
if (!A_IsCompiled) and InStr(s,"MCode(") and (cmd="Test")
{
s:="`n#NoEnv`nMenu, Tray, Click, 1`n"
. "Gui, FindText_ok_: Show, Hide, FindText_ok_`n"
. s "`nExitApp`n"
FindText_Gui("Exec")
DetectHiddenWindows, On
WinWait, FindText_ok_ ahk_class AutoHotkeyGUI,, 3
if (!ErrorLevel)
WinWaitClose,,, 30
}
else
{
Gui, +OwnDialogs
t:=A_TickCount, n:=150000
, RegExMatch(s,"\|<[^>\n]*>[^$\n]+\$\d+\.[\w+/]+",v)
, ok:=FindText(-n, -n, n, n, 0, 0, v)
, X:=ok.1.x, Y:=ok.1.y, Comment:=ok.1.id
MsgBox, 4096, Tip, % "Found :`t" Round(ok.MaxIndex()) "`n`n"
. "Time :`t" (A_TickCount-t) " ms`n`n"
. "Pos :`t" X ", " Y "`n`n"
. "Result:`t" (ok ? "Success ! " Comment : "Failed !"), 3
for i,v in ok
if (i<=2)
FindText_MouseTip(ok[i].x, ok[i].y)
ok:=""
}
;----------------------
Gui, Show
GuiControl, Focus, scr
return
}
if (cmd="Exec")
{
ListLines, %lls%
Ahk:=A_IsCompiled ? A_ScriptDir "\AutoHotkey.exe":A_AhkPath
s:=RegExReplace(s, "\R", "`r`n")
Try
{
shell:=ComObjCreate("WScript.Shell")
oExec:=shell.Exec(Ahk " /f /ErrorStdOut *")
oExec.StdIn.Write(s)
oExec.StdIn.Close(), oExec:="", shell:=""
}
catch
{
f:=A_Temp "\~test1.tmp"
s:="`r`n FileDelete, " f "`r`n" s
FileDelete, %f%
FileAppend, %s%, %f%
Run, %Ahk% /f "%f%",, UseErrorLevel
}
return
}
if (cmd="Copy")
{
ListLines, %lls%
Gui, FindText_Main: Default
ControlGet, s, Selected,,, ahk_id %hscr%
if (s="")
{
GuiControlGet, s,, scr
GuiControlGet, r,, AddFunc
if (r != 1)
s:=RegExReplace(s,"\n\K[\s;=]+ Copy The[\s\S]*")
}
Clipboard:=RegExReplace(s,"\R","`r`n")
;----------------------
Gui, Hide
Sleep, 100
Gui, Show
GuiControl, Focus, scr
return
}
if (cmd="Apply")
{
ListLines, %lls%
static FindText_FuncBind2:=Func("FindText_Gui").Bind("ScreenShot")
Gui, FindText_Main: Default
GuiControlGet, NowHotkey
GuiControlGet, SetHotkey1
GuiControlGet, SetHotkey2
if (NowHotkey!="")
Hotkey, *%NowHotkey%,, Off UseErrorLevel
k:=SetHotkey1!="" ? SetHotkey1 : SetHotkey2
if (k!="")
Hotkey, *%k%, %FindText_FuncBind2%, On UseErrorLevel
GuiControl,, NowHotkey, %k%
GuiControl,, SetHotkey1
GuiControl, Choose, SetHotkey2, 0
;------------------------
GuiControlGet, Myww
GuiControlGet, Myhh
if (Myww!=ww or Myhh!=hh)
{
Gui, Hide
ww:=Myww, hh:=Myhh, FindText_Gui("MakeSubPicWindow")
Gui, FindText_Main: Show, Center
}
return
}
if (cmd="ScreenShot")
{
ListLines, %lls%
Critical
FindText_ScreenShot()
Gui, FindText_Tip: New
; WS_EX_NOACTIVATE:=0x08000000, WS_EX_TRANSPARENT:=0x20
Gui, +LastFound +AlwaysOnTop +ToolWindow -Caption -DPIScale +E0x08000020
Gui, Color, Yellow
Gui, Font, cRed s48 bold
Gui, Add, Text,, Success
WinSet, Transparent, 200
Gui, Show, NA y0, ScreenShot Tip
Sleep, 1000
Gui, Destroy
return
}
if (cmd="Bind1"||cmd="Bind2")
{
ListLines, %lls%
FindText_BindWindow(Bind_ID, (cmd="Bind2"))
Hotkey, $*RButton, FindText_RButton_Off, On
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
CoordMode, Mouse
KeyWait, RButton
KeyWait, Ctrl
oldx:=oldy:=""
Loop
{
Sleep, 50
MouseGetPos, x, y
if (oldx=x and oldy=y)
Continue
oldx:=x, oldy:=y
;---------------
px:=x, py:=y, FindText_Gui("getcors",1)
FindText_Gui("Reset")
ToolTip, % "The Capture Position : " x "," y
. "`nPerspective binding window"
. "`nRight click to finish capture"
}
Until GetKeyState("RButton","P") or GetKeyState("Ctrl","P")
KeyWait, RButton
KeyWait, Ctrl
ToolTip
ListLines, %lls%
Hotkey, $*RButton, FindText_RButton_Off, Off
FindText_BindWindow(0), cors.bind:=(cmd="Bind2")
return
}
if (cmd="MySlider1"||cmd="MySlider2")
{
ListLines, %lls%
x:=SubPicW>PicW ? -(SubPicW-PicW)*MySlider1//100 : 0
y:=SubPicH>PicH ? -(SubPicH-PicH)*MySlider2//100 : 0
Gui, FindText_SubPic: Show, NA x%x% y%y%
return
}
if (cmd="Reset")
{
ListLines, %lls%
static ascii:=[], gray:=[], show:=[]
CutLeft:=CutRight:=CutUp:=CutDown:=k:=0, bg:=""
Loop, % nW*nH
{
show[++k]:=1, c:=cors[k]
gray[k]:=(((c>>16)&0xFF)*38+((c>>8)&0xFF)*75+(c&0xFF)*15)>>7
FindText_Gui("SetColor")
}
Loop, % cors.CutLeft
FindText_Gui("CutL")
Loop, % cors.CutRight
FindText_Gui("CutR")
Loop, % cors.CutUp
FindText_Gui("CutU")
Loop, % cors.CutDown
FindText_Gui("CutD")
return
}
if (cmd="SetColor")
{
ListLines, %lls%
c:=c="Black" ? 0x000000 : c="White" ? 0xFFFFFF
: ((c&0xFF)<<16)|(c&0xFF00)|((c&0xFF0000)>>16)
SendMessage, 0x2001, 0, c,, % "ahk_id " . C_[k]
return
}
if (cmd="RepColor")
{
ListLines, %lls%
show[k]:=1, c:=(bg="" ? cors[k] : ascii[k]
? "Black":"White"), FindText_Gui("SetColor")
return
}
if (cmd="CutColor")
{
ListLines, %lls%
show[k]:=0, c:=WindowColor, FindText_Gui("SetColor")
return
}
if (cmd="RepL")
{
ListLines, %lls%
if (CutLeft<=cors.CutLeft)
or (bg!="" and InStr(color,"**")
and CutLeft=cors.CutLeft+1)
return
k:=CutLeft-nW, CutLeft--
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? FindText_Gui("RepColor") : "")
return
}
if (cmd="CutL")
{
ListLines, %lls%
if (CutLeft+CutRight>=nW)
return
CutLeft++, k:=CutLeft-nW
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? FindText_Gui("CutColor") : "")
return
}
if (cmd="CutL3")
{
ListLines, %lls%
Loop, 3
FindText_Gui("CutL")
return
}
if (cmd="RepR")
{
ListLines, %lls%
if (CutRight<=cors.CutRight)
or (bg!="" and InStr(color,"**")
and CutRight=cors.CutRight+1)
return
k:=1-CutRight, CutRight--
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? FindText_Gui("RepColor") : "")
return
}
if (cmd="CutR")
{
ListLines, %lls%
if (CutLeft+CutRight>=nW)
return
CutRight++, k:=1-CutRight
Loop, %nH%
k+=nW, (A_Index>CutUp and A_Index<nH+1-CutDown
? FindText_Gui("CutColor") : "")
return
}
if (cmd="CutR3")
{
ListLines, %lls%
Loop, 3
FindText_Gui("CutR")
return
}
if (cmd="RepU")
{
ListLines, %lls%
if (CutUp<=cors.CutUp)
or (bg!="" and InStr(color,"**")
and CutUp=cors.CutUp+1)
return
k:=(CutUp-1)*nW, CutUp--
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? FindText_Gui("RepColor") : "")
return
}
if (cmd="CutU")
{
ListLines, %lls%
if (CutUp+CutDown>=nH)
return
CutUp++, k:=(CutUp-1)*nW
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? FindText_Gui("CutColor") : "")
return
}
if (cmd="CutU3")
{
ListLines, %lls%
Loop, 3
FindText_Gui("CutU")
return
}
if (cmd="RepD")
{
ListLines, %lls%
if (CutDown<=cors.CutDown)
or (bg!="" and InStr(color,"**")
and CutDown=cors.CutDown+1)
return
k:=(nH-CutDown)*nW, CutDown--
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? FindText_Gui("RepColor") : "")
return
}
if (cmd="CutD")
{
ListLines, %lls%
if (CutUp+CutDown>=nH)
return
CutDown++, k:=(nH-CutDown)*nW
Loop, %nW%
k++, (A_Index>CutLeft and A_Index<nW+1-CutRight
? FindText_Gui("CutColor") : "")
return
}
if (cmd="CutD3")
{
ListLines, %lls%
Loop, 3
FindText_Gui("CutD")
return
}
if (cmd="Gray2Two")
{
ListLines, %lls%
Gui, FindText_Capture: Default
GuiControl, Focus, Threshold
GuiControlGet, Threshold
if (Threshold="")
{
pp:=[]
Loop, 256
pp[A_Index-1]:=0
Loop, % nW*nH
if (show[A_Index])
pp[gray[A_Index]]++
IP:=IS:=0
Loop, 256
k:=A_Index-1, IP+=k*pp[k], IS+=pp[k]
Threshold:=Floor(IP/IS)
Loop, 20
{
LastThreshold:=Threshold
IP1:=IS1:=0
Loop, % LastThreshold+1
k:=A_Index-1, IP1+=k*pp[k], IS1+=pp[k]
IP2:=IP-IP1, IS2:=IS-IS1
if (IS1!=0 and IS2!=0)
Threshold:=Floor((IP1/IS1+IP2/IS2)/2)
if (Threshold=LastThreshold)
Break
}
GuiControl,, Threshold, %Threshold%
}
Threshold:=Round(Threshold)
color:="*" Threshold, k:=i:=0
Loop, % nW*nH
{
ascii[++k]:=v:=(gray[k]<=Threshold)
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), FindText_Gui("SetColor")
}
bg:=i>0 ? "1":"0"
return
}
if (cmd="GrayDiff2Two")
{
ListLines, %lls%
Gui, FindText_Capture: Default
GuiControlGet, GrayDiff
if (GrayDiff="")
{
Gui, +OwnDialogs
MsgBox, 4096, Tip, `nPlease Set Gray Difference First !`n, 1
return
}
if (CutLeft=cors.CutLeft)
FindText_Gui("CutL")
if (CutRight=cors.CutRight)
FindText_Gui("CutR")
if (CutUp=cors.CutUp)
FindText_Gui("CutU")
if (CutDown=cors.CutDown)
FindText_Gui("CutD")
GrayDiff:=Round(GrayDiff)
color:="**" GrayDiff, k:=i:=0
Loop, % nW*nH
{
j:=gray[++k]+GrayDiff
, ascii[k]:=v:=( gray[k-1]>j or gray[k+1]>j
or gray[k-nW]>j or gray[k+nW]>j
or gray[k-nW-1]>j or gray[k-nW+1]>j
or gray[k+nW-1]>j or gray[k+nW+1]>j )
if (show[k])
i:=(v?i+1:i-1), c:=(v?"Black":"White"), FindText_Gui("SetColor")
}
bg:=i>0 ? "1":"0"
return
}
if (cmd="Color2Two"||cmd="ColorPos2Two")
{
ListLines, %lls%
Gui, FindText_Capture: Default
GuiControlGet, c,, SelColor
if (c="")
{
Gui, +OwnDialogs
MsgBox, 4096, Tip, `nPlease select the core color first !`n, 1
return
}
UsePos:=(cmd="ColorPos2Two") ? 1:0
GuiControlGet, n,, Similar1
n:=Round(n/100,2), color:=c "@" n
, n:=Floor(9*255*255*(1-n)*(1-n)), k:=i:=0
, rr:=(c>>16)&0xFF, gg:=(c>>8)&0xFF, bb:=c&0xFF
Loop, % nW*nH