-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCowNinja_Functions.ahk
1425 lines (1229 loc) · 54.6 KB
/
CowNinja_Functions.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
; #####################################################################################
; FUNCTIONS OVERVIEW
; #####################################################################################
;
; find functions: ^[^\h][^\(\r\n\h]+\(
; or: ^([^\h\r\n\(]+\()
; or: ^([^\h\r\n\(]+\()|^([^\h\r\n\(]+\:)
;
; Win_GetInfo(App_Title:="", App_ID:="", App_Class:="", Options := ""){ ; Win_GetInfo(Options := ""){
; IsWindowVisible(App_Title) {
; WindowFromPoint(x, y)
; Win_WaitRegEX(WW_Title, WW_Text="", Timeout="", ExcludeTitle="", ExcludeText=""){
; OLD_Win_WaitRegEX(WW_Title, WW_Text="", Timeout="", ExcludeTitle="", ExcludeText=""){
; Control_GetInfo(Win_Control, Options := ""){
; Mouse_Click(X,Y, Options := "") {
; Key_Menu() {
; GUI_Update() {
; Mouse_Drag(X1, Y1, X2, Y2, Options := "") {
; Mouse_Move(X1, Y1, X2, Y2, Options := "") {
; Mouse_GetPos(Options := 3) {
; Mouse_MoveControl(X, Y, Control="", WinTitle="", WinText="", Options="", ExcludeTitle="", ExcludeText="", RelativeTo="Client", TargetType="Mouse") {
; Search_OCR(OCR_Array, Options := "") {
; DropFiles(window, files*)
; Search_Captured_Text_OCR(Search_Text_Array, Options := "") {
; Search_Pixels(Search_Pixels_Array, Options := "") {
; Search_Images(Search_Images_Array, Options := "") {
; Text_To_Log(ByRef Input_Array)
; Command_To_Screen(Text_To_Send, Options := "") {
; IsWindowChildOf(aChild, aParent) {
; EnumChildFindHwnd(aWnd, lParam) {
; EnumChildFindPoint(aWnd, lParam) {
; MsgBox(Message := "Press Ok to Continue.", Title := "", Type := 0, B1 := "", B2 := "", B3 := "", Time := "") {
; InputBox1(Title, Prompt, Options := "") {
; InputBox2(Title, Prompt, o := "") {
; RunWaitOne(command) {
; RunNoWaitOne(command) {
; RunWaitMany(commands) {
; RunDependent(target, workingdir:="", options:="", RunWait:=false){
; GetRandom(p_Input,p_Delim="",p_Omit=""){
; MsgBoxGetResult() {
; Convert_OCR_Value(RSS_VAR_OLD) {
; isEmptyOrEmptyStringsOnly(inputArray) {
; DateAdd(DateTime, Time, TimeUnits)
; DateDiff(DateTime1, DateTime2, TimeUnits)
; FormatTime(YYYYMMDDHH24MISS:="", Format:="")
; ClipBoard_Save() {
; ClipBoard_Restore() {
; Mouse_Save() {
; Mouse_Restore() {
; Window_Save() {
; Window_Restore() {
; All_Save() {
; All_Restore() {
;
; #####################################################################################
; ****************************************************************************
; ****************************************************************************
; allow users to use objects with the function and return the data they want.
; ****************************************************************************
; Examples:
; AppX := Win_GetInfo()
; MsgBox, 0, Win_GetInfo, % " Win_GetInfo " AppX.ID " " AppX.Class " " AppX.Title " " AppX.Ctrl
; or
; MsgBox, 0, Win_GetInfo, % " Win_GetInfo.X " Win_GetInfo().X " Win_GetInfo.Y " Win_GetInfo().Y
; ****************************************************************************
Win_GetInfo(App_Title:="", App_ID:="", App_Class:="", Options := ""){ ; Win_GetInfo(Options := ""){
; SetTitleMatchMode, RegEx
; MsgBox, 1. App_Title:"%App_Title%" FoundAppTitle:"%FoundAppTitle%" Get_App_Title:"%Get_App_Title%`nApp_ID:"%App_ID%" FoundAppID:"%FoundAppID%" Get_App_ID:"%Get_App_ID%"
if (App_Title = FoundAppTitle)
Get_App_Title := FoundAppTitle
if (App_ID = FoundAppID)
Get_App_ID = FoundAppID
; MsgBox, 2. App_Title:"%App_Title%" FoundAppTitle:"%FoundAppTitle%" Get_App_Title:"%Get_App_Title%`nApp_ID:"%App_ID%" FoundAppID:"%FoundAppID%" Get_App_ID:"%Get_App_ID%"
; Goal: to Get App ID
; Was an App ID passed to function? If So, use it
if !Get_App_ID
if !Get_App_Title
if !App_ID
if !App_Title
Get_App_ID := DllCall("GetParent", UInt,WinExist("A")), Get_App_ID := !Get_App_ID ? WinExist("A") : Get_App_ID
Else
Get_App_ID := Win_WaitRegEX(App_Title).ID
Else
Get_App_ID := App_ID
Else
Get_App_ID := Win_WaitRegEX(Get_App_Title).ID
; MsgBox, 3. App_Title:"%App_Title%" FoundAppTitle:"%FoundAppTitle%" Get_App_Title:"%Get_App_Title%`nApp_ID:"%App_ID%" FoundAppID:"%FoundAppID%" Get_App_ID:"%Get_App_ID%"
if !Get_App_ID
Get_App_ID := DllCall("GetParent", UInt,WinExist("A")), Get_App_ID := !Get_App_ID ? WinExist("A") : Get_App_ID
; MsgBox, 4. App_Title:"%App_Title%" FoundAppTitle:"%FoundAppTitle%" Get_App_Title:"%Get_App_Title%`nApp_ID:"%App_ID%" FoundAppID:"%FoundAppID%" Get_App_ID:"%Get_App_ID%"
/*
; old Openening
if App_Title
Get_App_ID := Win_WaitRegEX(App_Title).ID
else if App_ID
Get_App_ID := App_ID
else
Get_App_ID := DllCall("GetParent", UInt,WinExist("A")), Get_App_ID := !Get_App_ID ? WinExist("A") : Get_App_ID
*/
Get_Details_NOW:
WinGetTitle, Get_App_Title, ahk_id %Get_App_ID%
WinGetClass, Get_App_Class, ahk_id %Get_App_ID%
WinGetPos, App_X, App_Y, App_W, App_H, %Get_App_ID%
; MsgBox, 5. App_Title:"%App_Title%" FoundAppTitle:"%FoundAppTitle%" Get_App_Title:"%Get_App_Title%`nApp_ID:"%App_ID%" FoundAppID:"%FoundAppID%" Get_App_ID:"%Get_App_ID%"
; if Get_App_Class, FoundAppClass := Get_App_Class
; if Get_App_Title, FoundAppTitle := Get_App_Title
; if Get_App_ID, FoundAppID := Get_App_ID
Return {Title: Get_App_Title, ID: Get_App_ID, Class: Get_App_Class, X: App_X, Y: App_Y, W: App_W, H: App_H}
; MsgBox, (Initial) Title:"%App_Title%" ID:"%App_ID%" Class:"%App_Class%" X:"%App_X%" Y:"%App_Y%" W:"%App_W%" H:"%App_H%"
}
IsWindowVisible(App_Title) {
Get_App_ID := WinExist(App_Title)
If( ErrorLevel != 0 ) {
; MsgBox, Window %App_Title% not found!
return -1
}
If( Get_App_ID > 0 ) {
WinGetPos, App_X, App_Y, , , ahk_id %Get_App_ID%
active_window_id_hwnd := WindowFromPoint(App_X, App_Y)
; MsgBox, %App_X%, %App_Y%, %active_window_id_hwnd%
If( active_window_id_hwnd = Get_App_ID ) {
; MsgBox, Window %App_Title% is visible!
return 1
}
else {
; MsgBox, Window %App_Title% is NOT visible!
return 0
}
}
; MsgBox, Window %App_Title% not found!
return -1
}
WindowFromPoint(x, y)
{
VarSetCapacity(POINT, 8)
Numput(x, POINT, 0, "int")
Numput(y, POINT, 4, "int")
return DllCall("WindowFromPoint", int64, NumGet(POINT, 0, "int64"))
Return
}
; ****************************************************************************
; ****************************************************************************
; allow users to use objects with the function and return the data they want.
; ****************************************************************************
; Examples:
; Win_WaitRegEX("LEWZ")
; ****************************************************************************
Win_WaitRegEX(WW_Title="", WW_Text="", Timeout="", ExcludeTitle="", ExcludeText=""){
SetTitleMatchMode, RegEx
if (!WW_Title && !WW_Text)
{
MsgBox, 4, , empty!`nWW_Title:"%WW_Title%"`nWW_Text:"%WW_Text%" (4 Second Timeout & skip), 4
return
}
; MsgBox, 1. Begin, Title REGEX:"%WW_Title%"`nTitle Get:"%Win_WaitGetTitle%"`nTitle Found:"%FoundAppTitle%"`nID Get:"%Win_WaitGetID%"`nID Found:"%FoundAppID%"
; WinWait , WinTitle, WW_Text, Timeout, ExcludeTitle, ExcludeText
WinWait, %WW_Title%, %WW_Text%, %Timeout%, %ExcludeTitle%, %ExcludeText% ; Waits until the specified window exists.
if ErrorLevel
{
WW_Title := RegExReplace(WW_Title,"[^w]+")
WinWait, %WW_Title%, %WW_Text%, %Timeout%, %ExcludeTitle%, %ExcludeText% ; Waits until the specified window exists.
if ErrorLevel
return 0
}
Window_Save()
WinActivate, %WW_Title%, ; If not active, It activates it
WinWaitActive, %WW_Title% ; Waits until the specified window is active or not active.
WinGetTitle, Win_WaitGetTitle, A
Win_WaitGetID := DllCall("GetParent", UInt,WinExist("A")), Win_WaitGetID := !Win_WaitGetID ? WinExist("A") : Win_WaitGetID
; MsgBox, 2. Middle, Title REGEX:"%WW_Title%"`nTitle Get:"%Win_WaitGetTitle%"`nTitle Found:"%FoundAppTitle%"`nID Get:"%Win_WaitGetID%"`nID Found:"%FoundAppID%"
if WW_Title is alnum
if WinActive(%WW_Title%)
{
Win_WaitGetID := WinActive(%WW_Title%)
WinGetTitle, Win_WaitGetTitle, ahk_id %Win_WaitGetID%
WinActivate, ahk_id %Win_WaitGetID%, ; If not active, It activates it
WinWaitActive, ahk_id %Win_WaitGetID% ; Waits until the specified window is active or not active.
}
Window_Restore()
; MsgBox, 3. Finish, Title REGEX:"%WW_Title%"`nTitle Get:"%Win_WaitGetTitle%"`nTitle Found:"%FoundAppTitle%"`nID Get:"%Win_WaitGetID%"`nID Found:"%FoundAppID%"
Return {Title: Win_WaitGetTitle, ID: Win_WaitGetID}
}
; ****************************************************************************
OLD_Win_WaitRegEX(WW_Title, WW_Text="", Timeout="", ExcludeTitle="", ExcludeText=""){
SetTitleMatchMode, RegEx
MsgBox, 1. Begin, Title(REGEX:"%WW_Title%" Get:"%Win_WaitGetTitle%" Found:"%FoundAppTitle%" ID(Get:"%Win_WaitGetID%" Found:"%FoundAppID%")
; WinWait , WinTitle, WW_Text, Timeout, ExcludeTitle, ExcludeText
WinWait, %WW_Title%, %WW_Text%, %Timeout%, %ExcludeTitle%, %ExcludeText% ; Waits until the specified window exists.
If !WinActive(%WW_Title%) ; Checks if window exists and is currently active (foremost)
WinActivate, %WW_Title% ; If not active, It activates it
WinWaitActive, %WW_Title% ; Waits until the specified window is active or not active.
Win_WaitGetID := WinActive(%WW_Title%), if !(Win_WaitGetID = 0), FoundAppID := Win_WaitGetID
WinGetTitle, Win_WaitGetTitle, ahk_id %Win_WaitGetID%
if !(Win_WaitGetTitle = "")
FoundAppTitle := Win_WaitGetTitle
MsgBox, 2. Finish, Title(REGEX:"%WW_Title%" Get:"%Win_WaitGetTitle%" Found:"%FoundAppTitle%" ID(Get:"%Win_WaitGetID%" Found:"%FoundAppID%"
Return {Title: Win_WaitGetTitle, ID: Win_WaitGetID}
}
; ****************************************************************************
; ****************************************************************************
; allow users to use objects with the function and return the data they want.
; ****************************************************************************
; Examples:
; AppX := Control_GetInfo("Qt5QWindowIcon25", FoundAppTitle)
; MsgBox, 0, AppX, % " AppX " AppX.Text " " AppX.Hwnd " " AppX.X " " AppX.Y
; or
; MsgBox, 0, AppX, % " AppX.X " AppX().X " AppX.Y " AppX().Y
; ****************************************************************************
Control_GetInfo(Win_Control, Options := ""){
App_Title := (Options.HasKey("Title")) ? Options.Title : WinTitle
Win_ID := (Options.HasKey("ID")) ? Options.ID : DllCall("GetParent", UInt,WinExist(App_Title)), Win_ID := !Win_ID ? WinExist(App_Title) : Win_ID
ControlGetText, Control_Text, %Win_Control%, ahk_id %Win_ID%
ControlGet, Control_Hwnd, Hwnd,, %Win_Control%, ahk_id %Win_ID%
ControlGet, Control_Visible, Visible,, %Win_Control%, ahk_id %Win_ID%
ControlGet, Control_List, List,, %Win_Control%, ahk_id %Win_ID%
ControlGetPos, Control_X, Control_Y, Control_Width, Control_Height, %Win_Control%, ahk_id %Win_ID%
; MsgBox, (Initial) Text:"%Control_Text%" Hwnd:"%Control_Hwnd%" Visible:"%Control_Visible%" X:"%Control_X%" Y:"%Control_Y%" W:"%Control_Width%" H:"%Control_Height%"
Return {Text: Control_Text, Hwnd: Control_Hwnd, Visible: Control_Visible, List: Control_List, X: Control_X, Y: Control_Y, W: Control_Width, H: Control_Height}
}
; example: Mouse_Click(199, 250, {Clicks: 2, Delay: 50, Wait: 500})
; examples: Mouse_Click(155,299, {Clicks: 2, Timeout: 300})
; Mouse_Click(100,1000, {Clicks: 2, Timeout: 0}) ; Click On Donation Box 1
; Mouse_Click(100,1000, {DownUp: Down, Timeout: 0})
; Mouse_Click(100,1000, {DownUp: Up, Timeout: 0})
Mouse_Click(X,Y, Options := "") {
; generate a new random number between %rand_min% and %rand_max%
Random, rand_wait, %rand_min%, %rand_max%
Random, rand_pixel, %Min_Pix%, %Max_Pix%
; Win_Control := FoundAppControl
Win_Control := (Options.HasKey("Control")) ? Options.Control : FoundAppControl
Win_Title := (Options.HasKey("Title")) ? Options.Title : FoundAppTitle
Button := (Options.HasKey("Button")) ? Options.Button : "Left"
Clicks := (Options.HasKey("Clicks")) ? Options.Clicks : "1"
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : (3*Delay_Short+0)
DownUp := (Options.HasKey("DownUp")) ? Options.DownUp : ""
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Mouse"
; CoordMode Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Mouse, Relative ; Coordinates are relative to the active window.
; CoordMode Mouse, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Mouse, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
; msgbox, CoordMode`, %CoordModeTargetType%`, %CoordModeRelativeTo%
; MsgBox, Timeout:"%Timeout%", Clicks:"%Clicks%"
; MsgBox, 1. Mouse_Click input:(%X%:%Y%) initial:(%X_Pixel%:%Y_Pixel%) Rand_pixel:%rand_pixel% min-max(%Min_Pix%-%Max_Pix%)
; X++
; Y++
X_Pixel := (X + rand_pixel + X_Pixel_offset)
Y_Pixel := (Y + rand_pixel + Y_Pixel_offset)
; SendEvent {Click, %X_Pixel%, %Y_Pixel%} ; Where to click
; ControlClick, Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText
; ControlClick, x%X_Pixel% y%Y_Pixel%, %FoundAppTitle%,,,, Pos NA
; ControlClick, %Win_Control%, %FoundAppTitle%,, Left, 1, x%X_Pixel% y%Y_Pixel% NA
; ControlClick, Qt5QWindowIcon, LEWZ001,, Left, 1, x%X_Pixel% y%Y_Pixel% NA
SetControlDelay -1
; if !DownUp
ControlClick, %Win_Control%, %FoundAppTitle%,, %Button%, %Clicks%, x%X_Pixel% y%Y_Pixel% NA
; else if (DownUp = "Down")
; ControlClick, %Win_Control%, %FoundAppTitle%,, %Button%, %Clicks%, x%X_Pixel% y%Y_Pixel% NA D
; else if (DownUp = "Up")
; ControlClick, %Win_Control%, %FoundAppTitle%,, %Button%, %Clicks%, x%X_Pixel% y%Y_Pixel% NA U
DllCall("Sleep","UInt",Timeout) ; DllCall("Sleep","UInt",rand_wait + (3*Delay_Short))
GUI_Update()
; stdout.WriteLine(A_NowUTC " Executing Mouse_Click for FoundAppTitle:""" FoundAppTitle """ Subroutine:""" Subroutine_Running """ at (" X_Pixel "," Y_Pixel ") = Input:(" X "," Y ") + rand_pixel:(" rand_pixel ") + Pixel_offset:(" X_Pixel_offset "," Y_Pixel_offset ")" )
return
; MsgBox, 3. Mouse_Click input:(%X%:%Y%) incremented:(%X_Pixel%:%Y_Pixel%) Rand_pixel:%rand_pixel% min-max(%Min_Pix%-%Max_Pix%)
; MsgBox, ControlClick, %Win_Control%, %FoundAppTitle%,, %Button%, %Clicks%, x%X_Pixel% y%Y_Pixel% NA
; MsgBox, Mouse_Click input:(%X%:%Y%) math:(%X_Pixel%:%Y_Pixel%) Rand_pixel:%rand_pixel% min-max(%Min_Pix%-%Max_Pix%) Ctr:"%Win_Control%" or "%FoundAppControl%" Title:"%FoundAppTitle%" Button:"%Button%" Clicks:"%Clicks%" Timeout:"%Timeout%"
; stdout.WriteLine(A_NowUTC " Found " image_name " at " FoundPictureX "," FoundPictureY)
; WinActivate, %FoundAppTitle% ; Automatically uses the window found above.
; FileAppend, %A_NowUTC%`,A_ThisLabel`,%A_ThisLabel%`,Subroutine`,%Subroutine_Running%`,End time:`,%A_NowUTC%`r`n, %AppendCSVFile%
return
}
Key_Menu() {
Gui, Keys:New, , Keys
Gui, Keys:Margin, 0, 0
Gui, Keys:add,text,, F1 Switch App
Gui, Keys:add,text,, F3 Quick Collect
Gui, Keys:add,text,, F4 Exit Script
Gui, Keys:add,text,, F6 Reload Script
Gui, Keys:add,text,, CTRL+F6 Reload MEmu
; Gui, Keys:add,text,, F7 Reset_Posit = %Resetting_Posit% ; or (%Resetting_Posit% ? "True" : "False")
Gui, Keys:add,text,, % "F7 Reset_Posit = " (Resetting_Posit ? "Yes" : "No")
Gui, Keys:add,text,, F9 Exit Subroutine
Gui, Keys:add,text,, F10 Switch user
Gui, Keys:add,text,, % "Pause Script = " (A_IsPaused ? "Yes" : "No")
Gui, Keys:show, x731 y700 w150 h250
; ; WinActivate, %FoundAppTitle% ; Automatically uses the window found above.
; FileAppend, %A_NowUTC%`,A_ThisLabel`,%A_ThisLabel%`,Subroutine`,%Subroutine_Running%`,End time:`,%A_NowUTC%`r`n, %AppendCSVFile%
return
}
GUI_Update() {
if GUI_Count++>13
{
Gui, Status:new, , Status
Gui, Status:Margin, 0, 0
Gui, Status:add,text,, Account %User_Name%
if (Subroutine_Running = A_ThisLabel)
Gui, Status:add,text,, %Subroutine_Running% (%X_Pixel%,%Y_Pixel%)
Else
Gui, Status:add,text,, %Subroutine_Running%:%A_ThisLabel% (%X_Pixel%,%Y_Pixel%)
Gui, Status:show, x731 y0 w350 h500
GUI_Count := 0
}
if (Subroutine_Running = Last_Subroutine_Running)
{
; MsgBox, if equal: GUI_Count: %GUI_Count%, Subroutine_Running:%Subroutine_Running%, Last_Subroutine_Running: %Last_Subroutine_Running%
GUI_Count--
}
Else
{
; MsgBox, else: GUI_Count: %GUI_Count%, Subroutine_Running:%Subroutine_Running%, Last_Subroutine_Running: %Last_Subroutine_Running%
Last_Subroutine_Running := Subroutine_Running
; Gui, Status:add,text,, Click %image_name%
; Gui, Status:add,text,, Click %X_Pixel%, %Y_Pixel%
if (Subroutine_Running = A_ThisLabel)
Gui, Status:add,text,, %Subroutine_Running% (%X_Pixel%,%Y_Pixel%)
Else
Gui, Status:add,text,, %Subroutine_Running%:%A_ThisLabel% (%X_Pixel%,%Y_Pixel%)
Gui, Status:show, x731 y0 w350 h500
}
return
}
; example: Mouse_Drag(199, 250, 150, 300, {EndMovement: F, SwipeTime: 500})
Mouse_Drag(X1, Y1, X2, Y2, Options := "") {
Win_Control := (Options.HasKey("Control")) ? Options.Control : FoundAppControl
Win_Title := (Options.HasKey("Title")) ? Options.Title : FoundAppTitle
SwipeTime := (Options.HasKey("SwipeTime")) ? Options.SwipeTime : "1000"
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
EndMovement := (Options.HasKey("EndMovement")) ? Options.EndMovement : True
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Mouse"
; CoordMode Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Mouse, Relative ; Coordinates are relative to the active window.
; CoordMode Mouse, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Mouse, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
Steps := 16
X_Delta := (X2 - X1)
Y_Delta := (Y2 - Y1)
X_Step := round(X_Delta/Steps)+0 ; celi(number) ; round up, floor(number) ; round down
Y_Step := round(Y_Delta/Steps)+0 ; celi(number) ; round up, floor(number) ; round down
Move_X := X1
Move_Y := Y1
ControlClick, %Win_Control%, %FoundAppTitle%,,,, x%X1% y%Y1% D NA
DllCall("Sleep","UInt",(rand_wait + 1*Delay_Short))
loop, %Steps%
{
Move_X += X_Step
Move_Y += Y_Step
Mouse_MoveControl(Move_X, Move_Y, Win_Control, Win_Title, "", "L K")
DllCall("Sleep","UInt",(SwipeTime/Steps))
}
ControlClick, %Win_Control%, %FoundAppTitle%,,,, x%X2% y%Y2% U NA
if !EndMovement
return
Steps /= 2
loop, (%Steps%)
{
if (A_Index < (Steps/2))
{
Move_X += X_Step
Move_Y += Y_Step
}
if (A_Index >= (Steps/2))
{
Move_X -= X_Step
Move_Y -= Y_Step
}
if (Move_X <= 0)
Move_X := X2
if (Move_Y <= 0)
Move_Y := Y2
Mouse_MoveControl(Move_X, Move_Y, Win_Control, Win_Title, "", "L K")
DllCall("Sleep","UInt",(SwipeTime/Steps))
}
return
}
; example: Mouse_Move(199, 250, 150, 300, {Wait: 500})
Mouse_Move(X1, Y1, X2, Y2, Options := "") {
ClickCount := (Options.HasKey("Clicks")) ? Options.ClickCount : "1"
ClickDelay := (Options.HasKey("Delay")) ? Options.ClickDelay : "0"
ClickWait := (Options.HasKey("Wait")) ? Options.ClickWait : "0"
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Mouse"
; CoordMode Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Mouse, Relative ; Coordinates are relative to the active window.
; CoordMode Mouse, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Mouse, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
return
}
; ****************************************************************************
; ****************************************************************************
; allow users to use objects with the function and return the data they want.
; ****************************************************************************
; Examples:
; Data := Mouse_GetPos()
; MsgBox, 0, Mouse_GetPos, % " Mouse_GetPos " Data.X " " Data.Y " " Data.Win " " Data.Ctrl
; or
; MsgBox, 0, Mouse_GetPos, % " Mouse_GetPos.X " Mouse_GetPos().X " Mouse_GetPos.Y " Mouse_GetPos().Y
; ****************************************************************************
Mouse_GetPos(Options := 3) {
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Mouse"
; CoordMode Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Mouse, Relative ; Coordinates are relative to the active window.
; CoordMode Mouse, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Mouse, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
MouseGetPos, X, Y, Win, Ctrl, % Options
Return {X: X, Y: Y, Win: Win, Ctrl: Ctrl}
}
; Accepts coords relative to the specified window.
; X and Y MUST be specified, since current actual mouse location is irrelevant.
; Control:
; This can be, ClassNN, the name/text of the control, or a control HWND
; (which must be a child of the target window.)
; If a control HWND is specified, X and Y will be relative to the target
; window, not the child control.
; Options:
; a string of letters (spaces are optional) indicating which buttons("LMR X1 X2")/keys("S C"=shift,control) should be considered pressed.
; K: use actual key state for Shift and Ctrl.
; Return value:
; The hwnd of the control which was sent the mousemove message.
; Pass this to the Control parameter to simulate mouse capture.
; Based on AutoHotkey::script2.cpp::ControlClick()
Mouse_MoveControl(X, Y, Control="", WinTitle="", WinText="", Options="", ExcludeTitle="", ExcludeText="", RelativeTo="Client", TargetType="Mouse") {
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Mouse"
; CoordMode Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Mouse, Relative ; Coordinates are relative to the active window.
; CoordMode Mouse, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Mouse, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
; MsgBox, 1. WinTitle:"%WinTitle% Control:"%Control%" target_window:"%target_window%" X:"%X%" Y:"%Y%"
static EnumChildFindPointProc=0
if !EnumChildFindPointProc
EnumChildFindPointProc := RegisterCallback("EnumChildFindPoint","Fast")
if !(target_window := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText))
return false
if Control
{
if Control is integer
Control_is_hwnd := IsWindowChildOf(Control, target_window)
if Control_is_hwnd
{
; If %Control% specifies a control hwnd, send it the mouse move,
; but use coords relative to the window specified by WinTitle.
; This can be used to more easily simulate mouse capture.
control_window := Control
VarSetCapacity(rect, 16)
DllCall("GetWindowRect","uint",target_window,"uint",&rect)
VarSetCapacity(child_rect, 16)
DllCall("GetWindowRect","uint",control_window,"uint",&child_rect)
X -= NumGet(child_rect,0,"int") - NumGet(rect,0,"int")
Y -= NumGet(child_rect,4,"int") - NumGet(rect,4,"int")
}
else
ControlGet, control_window, Hwnd,, %Control%, ahk_id %target_window%
}
if (!control_window)
{
VarSetCapacity(rect, 16)
DllCall("GetWindowRect","uint",target_window,"uint",&rect)
VarSetCapacity(pah, 36, 0)
NumPut(X + NumGet(rect,0,"int"), pah,0,"int")
NumPut(Y + NumGet(rect,4,"int"), pah,4,"int")
DllCall("EnumChildWindows","uint",target_window,"uint",EnumChildFindPointProc,"uint",&pah)
control_window := NumGet(pah,24) ? NumGet(pah,24) : target_window
DllCall("ScreenToClient","uint",control_window,"uint",&pah)
X:=NumGet(pah,0,"int"), Y:=NumGet(pah,4,"int")
}
wParam := (InStr(Options,"L") ? 0x1 : 0) || (InStr(Options,"M") ? 0x10 : 0) || (InStr(Options,"R") ? 0x2 : 0)
|| (InStr(Options,"X1") ? 0x20 : 0) || (InStr(Options,"X2") ? 0x40 : 0)
|| (InStr(Options,"S") ? 0x4 : 0) || (InStr(Options,"C") ? 0x8 : 0)
|| (InStr(Options,"K") ? (GetKeyState("Shift") ? 0x4:0)|(GetKeyState("Control") ? 0x8:0) : 0)
PostMessage, 0x200, wParam, (x & 0xFFFF) | ((y & 0xFFFF)<<16),, ahk_id %control_window%
return control_window
}
; example: Search_OCR("Wages")
; example: Search_OCR("Wages", {X1: 115, Y1: 30, W: 560, H: 75, Timeout: 8})
; example: Search_OCR(ArrayOfText, {X1: 115, Y1: 30, X2: 259, Y2: 60, Timeout: 1})
Search_OCR(OCR_Array, Options := "") {
X1 := (Options.HasKey("X1")) ? Options.X1 : "115"
Y1 := (Options.HasKey("Y1")) ? Options.Y1 : "30"
W := (Options.HasKey("W")) ? Options.W : "560"
H := (Options.HasKey("H")) ? Options.H : "75"
X2 := (Options.HasKey("X2")) ? Options.X2 : (X1 + W)
Y2 := (Options.HasKey("Y2")) ? Options.Y2 : (Y1 + H)
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
return
}
;window = target window, standard AHK window syntax works eg: ahk_id hwnd or just WinTitle
;files = list of files to be dropped
DropFiles(window, files*)
{
for k,v in files
memRequired+=StrLen(v)+1
hGlobal := DllCall("GlobalAlloc", "uint", 0x42, "ptr", memRequired+21)
dropfiles := DllCall("GlobalLock", "ptr", hGlobal)
NumPut(offset := 20, dropfiles+0, 0, "uint")
for k,v in files
StrPut(v, dropfiles+offset, "utf-8"), offset+=StrLen(v)+1
DllCall("GlobalUnlock", "ptr", hGlobal)
PostMessage, 0x233, hGlobal, 0,, %window%
if ErrorLevel
DllCall("GlobalFree", "ptr", hGlobal)
}
; example: Search_Captured_Text_OCR(["Wages"], {Pos: [115, 30], Size: [560, 60], Timeout: 8})
Search_Captured_Text_OCR(Search_Text_Array, Options := "") {
if (isEmptyOrEmptyStringsOnly(Search_Text_Array))
{
Timeout := 8
goto Search_Captured_Text_MessageBox
}
highlight_OCR := False ; True ;
Win_Control := (Options.HasKey("Control")) ? Options.Control : FoundAppControl
Win_Title := (Options.HasKey("Title")) ? Options.Title : FoundAppTitle
OCR_X1 := (Options.HasKey("Pos")) ? Options.Pos[1] : "200" ; "185" ; "115"
OCR_Y1 := (Options.HasKey("Pos")) ? Options.Pos[2] : "40" ; "54" ; "30"
OCR_W := (Options.HasKey("Size")) ? Options.Size[1] : "300" ; "450" ; "560"
OCR_H := (Options.HasKey("Size")) ? Options.Size[2] : "30" ; "28" ; "75"
OCR_X2 := (OCR_X1 + OCR_W ) ; + X_Pixel_offset)
OCR_Y2 := (OCR_Y1 + OCR_H ) ; + Y_Pixel_offset)
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : 0 ; "8"
Search_Captured_Text_Begin:
; WinRestore, %FoundAppTitle%
; PostMessage, 0x112, 0xF120,,, %FoundAppTitle% ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE
; WinShow
; if !WinActive(%FoundAppTitle%), WinActivate, %FoundAppTitle%
; if WinExist(FoundAppTitle), WinRestore
; ControlFocus, %FoundAppControl%, %FoundAppTitle%
; if !IsWindowVisible(App_Title)
; Win_WaitRegEX(FoundAppTitle)
/*
is_visible := IsWindowVisible(FoundAppTitle)
If( is_visible > 0 )
{
; MsgBox, Window %FoundAppTitle% is visible!
; Win_WaitRegEX(FoundAppTitle)
Sleep, 0
}
else If( is_visible < 0 )
{
; MsgBox, Window %FoundAppTitle% not found!
return False
}
else
{
; MsgBox, Window %FoundAppTitle% is NOT visible!
Win_WaitRegEX(FoundAppTitle)
}
*/
; ClipBoard_Save()
; Gosub Capture2Text_CLI
; Gosub Capture2Text_EXE
Capture_Screen_Text := OCR([OCR_X1, OCR_Y1, OCR_W, OCR_H], "eng")
if highlight_OCR
{
CreateBox("FF0000")
Box(OCR_X1, OCR_Y1, OCR_W, OCR_H, 2, "in")
; DllCall("Sleep","UInt",(3*Delay_Short+0))
; DllCall("Sleep","UInt",(1*Delay_Medium+0))
}
/*
Loop
{
MouseGetPos, , , Window, Control, 2
WinGetPos, x1, y1, , , ahk_id %Window%
ControlGetPos, x, y, w, h, , ahk_id %Control%
Box(x + x1, y + y1, w, h, 2, "in")
Sleep 100
}
*/
; ClipBoard_Restore()
if( Capture_Screen_Text != "")
{
; Capture_Screen_Text_Display := RegExReplace(Capture_Screen_Text,"[\r\n\h]+")
Gui, Status:add,text,, % "OCR:" RegExReplace(Capture_Screen_Text,"[\r\n]+")
; Gui, Status:add,text,, % "OCR Text:" Capture_Screen_Text
; Gui, Status:add,text,, % "OCR Text:""" Capture_Screen_Text """"
Gui, Status:show, x731 y0 w300 h500
GUI_Count++
GUI_Update()
}
if highlight_OCR
{
MsgBox, 0, Pause, Press OK to end (No Timeout)
RemoveBox()
}
For index, value in Search_Text_Array
{
; MsgBox, %Subroutine_Running% (%OCR_X1%,%OCR_Y1%,%OCR_W%,%OCR_H%) index:"%index%"`nSearch:"%value%" `nFound:"%Capture_Screen_Text%"`nWin_Control:"%Win_Control%" FoundAppControl:"%FoundAppControl%" FoundAppTitle:"%FoundAppTitle%"
if !( value == "" )
If (RegExMatch(Capture_Screen_Text,value))
Return {Found: True, Value: value, Text: Capture_Screen_Text} ; return 1
}
Goto Search_Captured_Text_END
Search_Captured_Text_END:
if (Timeout = 0)
Return {Found: False, Value: False, Text: Capture_Screen_Text} ; return 0
Search_Captured_Text_MessageBox:
MsgBox, 4, , "%Search_Captured_Text%" not detected`, try again? (%Timeout% Second Timeout & skip), %Timeout%
vRet := MsgBoxGetResult()
if (vRet = "Timeout") || if (vRet = "No")
Return {Found: False, Value: False, Text: Capture_Screen_Text} ; return 0
if (vRet = "Yes")
goto Search_Captured_Text_Begin
; FileAppend, %A_NowUTC%`,A_ThisLabel`,%A_ThisLabel%`,Subroutine`,%Subroutine_Running%`,End time:`,%A_NowUTC%`r`n, %AppendCSVFile%
Return {Found: False, Value: False, Text: Capture_Screen_Text} ; return 0
/*
; old Search captured text
For index, value in Search_Text_Array
{
; MsgBox, (%OCR_X1%,%OCR_Y1%) (%OCR_W%,%OCR_H%) index:%index% value:%value% Capture_Screen_Text:%Capture_Screen_Text%
if !( value == "" )
{
; MsgBox, Found index:%index% value:%value% Capture_Screen_Text:%Capture_Screen_Text%
If (RegExMatch(Capture_Screen_Text,value))
return 1
}
; else
; MsgBox, NOTFound index:%index% value:%value% Capture_Screen_Text:%Capture_Screen_Text%
}
*/
Capture2Text_CLI:
{
Capture2TextRUN := Capture2TextPATH . Capture2TextCLI
Capture_Screen_Text := Clipboard := ""
; Capture2Text_Coords := """" . OCR_X1 . " " . OCR_Y1 . " " . OCR_X2 . " " . OCR_Y2 . """"
Capture2Text_Coords := OCR_X1 . " " . OCR_Y1 . " " . OCR_X2 . " " . OCR_Y2
Run, %Capture2TextRUN% --screen-rect "%Capture2Text_Coords%" --clipboard
ClipWait, 3
Capture_Screen_Text := Clipboard
return
Process, Exist, %Capture2TextCLI% ; check to see if running
If (ErrorLevel != 0) ; If is running, close
Process, Close, %ErrorLevel%
; full_command := "%Capture2TextRUN% --screen-rect %Capture2Text_Coords% --clipboard"
full_command := Capture2TextRUN . " --screen-rect " . Capture2Text_Coords . " --clipboard"
; full_command := Capture2TextRUN . " --screen-rect " . Capture2Text_Coords
Capture_Screen_Text := % RunWaitOne(full_command)
; RunWait, %comspec% /c %full_command%, , hide
; msgbox, 1. %ErrorLevel%: Capture_Screen_Text:"%Capture_Screen_Text%" Clipboard:"%Clipboard%"
; DllCall("Sleep","UInt",rand_wait + (3*Delay_Short))
Capture_Screen_Text := Clipboard
; msgbox, 2. %ErrorLevel%: Capture_Screen_Text:"%Capture_Screen_Text%" Clipboard:"%Clipboard%"
; Capture_Screen_Text := RunWaitOne(full_command)
; msgbox, 2. Capture_Screen_Text:"%Capture_Screen_Text%" Clipboard:"%Clipboard%"
; Capture_Screen_Text := Clipboard
; MsgBox, runwait, %comspec% /c %full_command%
return
}
Capture2Text_EXE:
{
Capture2TextRUN := Capture2TextPATH . Capture2TextEXE
Capture_Screen_Text :=
Process, Exist, %Capture2TextEXE% ; check to see if running
If (ErrorLevel = 0) ; If not running
RunWaitOne(Capture2TextRUN)
Clipboard := ""
; Sleep, 500
Click, %OCR_X1%, %OCR_Y1%, 0
; Sleep, 50
Send, {LControl Down}{LAlt Down}{q}{LAlt Up}{LControl Up}
; Sleep, 50
Click, %OCR_X2%, %OCR_Y2%, 0
Sleep, 100
Send, {LControl Down}{LAlt Down}{q}{LAlt Up}{LControl Up}
ClipWait, 3
; MsgBox, 0, , %Clipboard%`n(%OCR_X1%,%OCR_Y1%) to (%OCR_X2%,%OCR_Y2%)
Capture_Screen_Text := clipboard
return
}
; Goto Search_Captured_Text_END
}
CreateBox(Color)
{
Gui 81:color, %Color%
Gui 81:+ToolWindow -SysMenu -Caption +AlwaysOnTop
Gui 82:color, %Color%
Gui 82:+ToolWindow -SysMenu -Caption +AlwaysOnTop
Gui 83:color, %Color%
Gui 83:+ToolWindow -SysMenu -Caption +AlwaysOnTop
Gui 84:color, %Color%
Gui 84:+ToolWindow -SysMenu -Caption +AlwaysOnTop
}
Box(XCor, YCor, Width, Height, Thickness, Offset)
{
If InStr(Offset, "In")
{
StringTrimLeft, offset, offset, 2
If not Offset
Offset = 0
Side = -1
} Else {
StringTrimLeft, offset, offset, 3
If not Offset
Offset = 0
Side = 1
}
x := XCor - (Side + 1) / 2 * Thickness - Side * Offset
y := YCor - (Side + 1) / 2 * Thickness - Side * Offset
h := Height + Side * Thickness + Side * Offset * 2
w := Thickness
Gui 81:Show, x%x% y%y% w%w% h%h% NA
x += Thickness
w := Width + Side * Thickness + Side * Offset * 2
h := Thickness
Gui 82:Show, x%x% y%y% w%w% h%h% NA
x := x + w - Thickness
y += Thickness
h := Height + Side * Thickness + Side * Offset * 2
w := Thickness
Gui 83:Show, x%x% y%y% w%w% h%h% NA
x := XCor - (Side + 1) / 2 * Thickness - Side * Offset
y += h - Thickness
w := Width + Side * Thickness + Side * Offset * 2
h := Thickness
Gui 84:Show, x%x% y%y% w%w% h%h% NA
}
RemoveBox()
{
Gui 81:destroy
Gui 82:destroy
Gui 83:destroy
Gui 84:destroy
}
DrawRectangle(hdc, left, top, right, bottom) { ;-- used DLLCall to draw a rectangle
DllCall("MoveToEx", Int, hdc, Int, left, Int, top, UInt, 0)
DllCall("LineTo", Int, hdc, Int, right, Int, top)
DllCall("LineTo", Int, hdc, Int, right, Int, bottom)
DllCall("LineTo", Int, hdc, Int, left, Int, bottom)
DllCall("LineTo", Int, hdc, Int, left, Int, top-1)
return
}
; example: Search_Pixels("OxFf4B2C", {X1: 115, Y1: 30, W: 560, H: 75, Timeout: 8})
; example: Search_Pixels(ArrayOfColors, {X1: 115, Y1: 30, X2: 259, Y2: 60, Timeout: 1})
Search_Pixels(Search_Pixels_Array, Options := "") {
X1 := (Options.HasKey("X1")) ? Options.X1 : Client_Area_X1
Y1 := (Options.HasKey("Y1")) ? Options.Y1 : Client_Area_W1
W := (Options.HasKey("W")) ? Options.W : Client_Area_W
H := (Options.HasKey("H")) ? Options.H : Client_Area_H
X2 := (Options.HasKey("X2")) ? Options.X2 : Client_Area_X2
Y2 := (Options.HasKey("Y2")) ? Options.Y2 : Client_Area_Y2
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Pixel"
; CoordMode Pixel, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Pixel, Relative ; Coordinates are relative to the active window.
; CoordMode Pixel, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Pixel, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
return
}
; example: Search_Images("OK_Button.jpg", {X1: 115, Y1: 30, W: 560, H: 75, Timeout: 8})
; example: Search_Images(ArrayOfImages, {X1: 115, Y1: 30, X2: 259, Y2: 60, Timeout: 1})
Search_Images(Search_Images_Array, Options := "") {
X1 := (Options.HasKey("X1")) ? Options.X1 : Client_Area_X1
Y1 := (Options.HasKey("Y1")) ? Options.Y1 : Client_Area_W1
W := (Options.HasKey("W")) ? Options.W : Client_Area_W
H := (Options.HasKey("H")) ? Options.H : Client_Area_H
X2 := (Options.HasKey("X2")) ? Options.X2 : Client_Area_X2
Y2 := (Options.HasKey("Y2")) ? Options.Y2 : Client_Area_Y2
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
CoordModeRelativeTo := (Options.HasKey("RelativeTo")) ? Options.RelativeTo : "Client" ; "Window"
CoordModeTargetType := (Options.HasKey("TargetType")) ? Options.TargetType : "Pixel"
; CoordMode Pixel, Screen ; Coordinates are relative to the desktop (entire screen).
; CoordMode Pixel, Relative ; Coordinates are relative to the active window.
; CoordMode Pixel, Window ; Synonymous with Relative and recommended for clarity.
; CoordMode Pixel, Client ; Coordinates are relative to the active window's client area, which excludes the window's title bar, menu (if it has a standard one) and borders. Client coordinates are less dependent on OS version and theme.
CoordMode, %CoordModeTargetType%, %CoordModeRelativeTo%
return
}
; example: Command_To_Screen("UserName")
; example: Text_To_Diag("UserName")
; example: Text_To_CSV("UserName")
; example: Text_To_Log("UserName")
; example: Text_To_GUI("UserName")
; example: Text_To_Status("UserName")
; Example: Text_To_Log([FoundAppTitle,FoundAppClass,FoundAppControl,FoundAppProcess])
Text_To_Log(ByRef Input_Array)
{
Output1 := Output2 := A_NowUTC ","
For VAR,Val in Input_Array
{
if Val
VAR_NAME := %Val%
if VAR_NAME
Output1 .= %VAR_NAME% . ","
Output1 .= VAR . "," . %VAR% . "," . Val . "," . %Val% . ","
Output2 .= &VAR . "," . &%VAR% . "," . &Val . "," . &%Val% . ","
VAR_Contents2 := Val[A_Index] ; Val%A_Index%
; Output1 .= VAR_NAME . ",""" . VAR_Contents1 . ""","
; Output2 .= VAL_NAME . ",""" . VAR_Contents2 . ""","
MsgBox, %A_Index%. VAR:Val"%VAR%:%Val%"`nVAR:Val"&%VAR%:&%Val%"`nNAME:"%VAR_NAME%"`nContents:"%VAR_Contents1%"`n1:%Output1%`n2:%Output2%
}
stdout.WriteLine("Output1," Output1)
stdout.WriteLine("Output2," Output2)
return
}
Command_To_Screen(Text_To_Send, Options := "") {
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
Win_Control := (Options.HasKey("Control")) ? Options.Control : FoundAppControl ; "ahk_parent"
Win_Title := (Options.HasKey("Title")) ? Options.Title : FoundAppTitle
ControlSend, %Win_Control%, %Text_To_Send%, %Win_Title%
/*
If (RegExMatch(Text_To_Send,"^[{}\!\^]+"))
{
ControlSend, %Win_Control%, %Text_To_Send%, %Win_Title%
; DllCall("Sleep","UInt",(rand_wait + 1*Delay_Long))
; MsgBox, ControlSend, %Win_Control%, %Text_To_Send%, %Win_Title%
} Else {
ClipBoard_Save()
; ClipSave := Clipboard, Clipboard := ""
Clipboard := Text_To_Send
ClipWait, 3
ControlSend, %Win_Control%, ^v, %Win_Title%
ClipBoard_Restore()
; Clipboard := ClipSave, ClipSave := ""
; DllCall("Sleep","UInt",(rand_wait + 1*Delay_Long))
; MsgBox, ControlSend, %Win_Control%, ^v, %Win_Title%
}
*/
; Timeout += (StrLen(Text_To_Send) * 1+Delay_Micro)
; DllCall("Sleep","UInt",Timeout+1) ; Sleep, 500
return
}
Text_To_Screen(Text_To_Send, Options := "") {
Timeout := (Options.HasKey("Timeout")) ? Options.Timeout : "0"
Win_Control := (Options.HasKey("Control")) ? Options.Control : FoundAppControl ; "ahk_parent"
Win_Title := (Options.HasKey("Title")) ? Options.Title : FoundAppTitle
ClipBoard_Save()
; ClipSave := Clipboard, Clipboard := ""
Clipboard := Text_To_Send
ClipWait, 3
SetKeyDelay, 20, 20 ; -1 ; default
ControlSend, %Win_Control%, ^v, %Win_Title%
; ControlSend, %Win_Control%, {ctrl down}v{ctrl up}, %Win_Title%
SetKeyDelay, -1 ; -1 ; default
ClipBoard_Restore()
; Clipboard := ClipSave, ClipSave := ""
; DllCall("Sleep","UInt",(rand_wait + 1*Delay_Long))
; MsgBox, ControlSend, %Win_Control%, ^v, %Win_Title%
; Timeout += (StrLen(Text_To_Send) * 1+Delay_Micro)
; DllCall("Sleep","UInt",Timeout+1) ; Sleep, 500
return
}
IsWindowChildOf(aChild, aParent) {
static EnumChildFindHwndProc=0
if !EnumChildFindHwndProc
EnumChildFindHwndProc := RegisterCallback("EnumChildFindHwnd","Fast")
VarSetCapacity(lParam,8,0), NumPut(aChild,lParam,0)
DllCall("EnumChildWindows","uint",aParent,"uint",EnumChildFindHwndProc,"uint",&lParam)
return NumGet(lParam,4)
}
EnumChildFindHwnd(aWnd, lParam) {
if (aWnd = NumGet(lParam+0))