-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unofficial Macro Recorder.ahk
2516 lines (2099 loc) · 59 KB
/
Unofficial Macro Recorder.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
/*
-----------------------------------
Unofficial Macro Recorder 3.0 (by Speedmaster)
original post "Macro Recorder" By FeiYue
Warning ! This is a modified version of Macro Recorder v1.6 (by Feiyue)
and contains Findtext tool v5.2 (by Feiyue)
Macro Recorder post:(by Feiyue)
https://autohotkey.com//boards/viewtopic.php?f=6&t=34184
FindText post:(by Feiyue)
https://autohotkey.com/boards/viewtopic.php?f=6&t=17834
Description:
1. This script records the mouse and keyboard
actions and then plays back.
2. Individually press LCtrl to record mouse movement.
3. Move the mouse to the top left corner
of the screen to pop up the menu.
4. If you want to stop playback process,
please press the Pause hotkey first,
and then click the Stop button.
Pause Button --> Pause Record/Play (Better to use hotkey)
Record Button --> Record Mouse/Keyboard/Window/Delay
Stop Button --> Stop Record/Play (Save To LogFile)
Play Button --> Play LogFile
Edit Button --> Edit LogFile
Loop Play CheckBox --> Loop playback options
Relative CheckBox --> relative coordinates options
Pause Hotkey --> Pause Record/Play
-----------------------------------
*/
#NoEnv
#SingleInstance force
SetBatchLines, -1
CoordMode, Mouse
CoordMode, ToolTip
;PREFERENCES:
;----------------------------------
ScriptVersion=v3.0
LogFile = %A_Scriptdir%\~Macro.ahk
EditorPath = notepad.exe ;put here the path to your default editor for ex. "C:\Program Files\AutoHotkey\SciTE\SciTE.exe"
AutoScriptWriterPath = % SubStr( A_AhkPath, 1, -14 ) . "AutoScriptWriter\AutoScriptWriter.exe" ; put here the path to AutoScriptWriter II
StartRecordDelay := 1000 ; waiting time (in millisec) before begining to record
SleepDelay := 2000 ; Max time (in millisec) for sleep command
WinWaitDelay := 3 ; time (in sec) for winwait command
beepsound := 1 ; Emits a tone from the PC speaker on record
EditAfterRecord := 0 ; Show internal editor after record
TooltipMessage := 1 ; append tooltip messages to macro
AppendClass := 1 ; append class name to window title
SplitLines := 0 ; auto split long lines of keyborad recording
ShowASWIIbuttons := 0 ; Hide/Show AutoScriptWriter II buttons
ActivateFindtext := 1 ; Hide/Show Findtext button and activate findtext tool
ShowMenuButton := 1 ; Hide/Show Disable Menu Button
ShowExitButton := 1 ; Hide/Show Exit Button from the menu
ShowSetupButton := 1
CoordMouseWindow := 1
RecordasVkSc := 0 ; record inputs as VkSc code exept keys in excludevksc list
ExcludeVkSc := "NumpadEnter,Home,End,PgUp,PgDn,Left,Right,Up,Down,Del,Ins,LButton,RButton,CtrlBreak,MButton,XButton1,XButton2,Backspace,Tab,NumpadClear,Enter,Pause,CapsLock,Esc,Space,NumpadPgUp,NumpadPgDn,NumpadEnd,NumpadHome,NumpadLeft,NumpadUp,NumpadRight,NumpadDown,PrintScreen,NumpadIns,NumpadDel,Help,,LWin,RWin,AppsKey,Sleep,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadMult,NumpadAdd,NumpadSub,NumpadDot,NumpadDiv,CapsLock,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,Numlock,ScrollLock,WheelLeft,WheelRight,WheelDown,WheelUp,LShift,RShift,LCtrl,RCtrl,LAlt,RAlt,Browser_Back,Browser_Forward,Browser_Refresh,Browser_Stop,Browser_Search,Browser_Favorites,Browser_Home,Volume_Mute,Volume_Down,Volume_Up,Media_Next,Media_Prev,Media_Stop,Media_Play_Pause,Launch_Mail,Launch_Media,Launch_App1,Launch_App2"
startmode = 1 ; start with menu closed (default)
startmode = 2 ; show menu at startup
startmode = 3 ; don't show the menu (=stealth mode)
startmode = 1 ; put here your default start value
splashscreen := 1 ; Display startup splash screen
guicolor :="FFFFAA"
displayicons := 1 ; Display icons in menu buttons
EditorFontSize:=9
;hotkeys
Hotkey, *Pause, Pause
Hotkey, F6 & F4, ToggleMenu
Hotkey, F6 & F5, Record
Hotkey, F6, Stop
Hotkey, F6 & F7, Play
Hotkey, F6 & F8, toggleLoopPlay
Hotkey, F6 & F9, toggleMouseRelative
Hotkey, F6 & F10, Edit
Hotkey, ~RButton, ToggleMenuR
;Append code to header
header=
(
)
;Append code to footer
footer=
(
)
;Append code to mouse click
Append_to_Click=
(
)
;----------------------------------
Shortcuts=
(
Pause >> Pause
F6 + F4 >> Toggle Show Menu
Double Right click
on left edge of
screen >> Toggle Show Menu
F6 + F5 >> Record
F6 >> Stop Recording or Playing
F6 + F7 >> Play Macro
F6 + F8 >> Toggle Repeat
F6 + F9 >> Toggle Mouse Relative to Window
F6 + F10 >> Editor
F12 >> Reload
)
;---------------------------------------CHECK IF INI EXIST IF NOT CREATE IT--------------------------------------------------------
iniFile := SubStr( A_ScriptName, 1, -3 ) . "ini"
Ini_File=%A_WorkingDir%\%iniFile%
;msgbox, %Ini_File%
ifnotexist,%Ini_File%
{
iniContent =
(
[]
;File path
-----------------------------------------------------
LogFile=%LogFile%
EditorPath=%EditorPath%
AutoScriptWriterPath=%AutoScriptWriterPath%
;macro file options
------------------------------------------------------
SleepDelay=%SleepDelay%
WinWaitDelay=%WinWaitDelay%
TooltipMessage=%TooltipMessage%
AppendClass=%AppendClass%
CoordMouseWindow=%CoordMouseWindow%
SplitLines=%SplitLines%
EditAfterRecord=%EditAfterRecord%
RecordasVkSc=%RecordasVkSc%
ExcludeVkSc="NumpadEnter,Home,End,PgUp,PgDn,Left,Right,Up,Down,Del,Ins,LButton,RButton,CtrlBreak,MButton,XButton1,XButton2,Backspace,Tab,NumpadClear,Enter,Pause,CapsLock,Esc,Space,NumpadPgUp,NumpadPgDn,NumpadEnd,NumpadHome,NumpadLeft,NumpadUp,NumpadRight,NumpadDown,PrintScreen,NumpadIns,NumpadDel,Help,,LWin,RWin,AppsKey,Sleep,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadMult,NumpadAdd,NumpadSub,NumpadDot,NumpadDiv,CapsLock,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,Numlock,ScrollLock,WheelLeft,WheelRight,WheelDown,WheelUp,LShift,RShift,LCtrl,RCtrl,LAlt,RAlt,Browser_Back,Browser_Forward,Browser_Refresh,Browser_Stop,Browser_Search,Browser_Favorites,Browser_Home,Volume_Mute,Volume_Down,Volume_Up,Media_Next,Media_Prev,Media_Stop,Media_Play_Pause,Launch_Mail,Launch_Media,Launch_App1,Launch_App2"
;use ``n as multiline separator to append some code to header footer or mouse clicks
header=%header%
footer=%footer%
Append_to_Click=%Append_to_Click%
;Interface
-------------------------------------------------------
;startmode 1 start with menu closed (default) ;mode 2 show menu at startup ;mode 3 don't show the menu (=stealth mode)
startmode=%startmode%
splashscreen=%splashscreen%
displayicons=%displayicons%
guicolor=%guicolor%
beepsound=%beepsound%
StartRecordDelay=%StartRecordDelay%
; show Findtext5.2 tool (by Feiyue)
ActivateFindtext=%ActivateFindtext%
; (ASWII) AutoScriptWriter II - ( by Larry Keys )
ShowASWIIbuttons=%ShowASWIIbuttons%
)
replaceFile(iniFile, iniContent)
}
; call replace file function
replaceFile(File, Content)
{
FileDelete, %File%
FileAppend, %Content%, %File%
}
;------------------------------------Read the ini file and store its content to variables----------------------------------------------
;Call function ini
updateini()
;----------------------------------------------------------------------------------------
StringReplace, header, header, ``n, `n, All
StringReplace, footer, footer, ``n, `n, All
StringReplace, Append_to_Click, Append_to_Click, ``n, `n, All
;-----------------------------------
Gui 1: +AlwaysOnTop -Caption +ToolWindow +Hwndgui_id +E0x08000000
Gui 1: Color, %guicolor% ;FFFFAA
Gui 1: Margin, 0, 0
if !displayicons
{
Gui 1: Font, s12, Verdana
Gui 1: Add, Button, w120 h60 section gPause, Pause
Gui 1: Add, Button, wp hp gRecord, Record
Gui 1: Add, Button, wp hp gStop, Stop
Gui 1: Add, Button, wp hp gPlay, Play
Gui 1: Add, Button, wp hp gEdit, Edit
if ActivateFindtext
Gui 1: Add, Button, wp hp gfindtext, Find Picture
}
if displayicons
{
Gui 1: Font, s30 cbold, Webdings
Gui 1: Add, Button, w120 h60 section gPause, % chr(0x3B)
Gui 1: Add, Button, wp hp gRecord, % chr(0x3D)
Gui 1: Add, Button, wp hp gStop, % chr(0x3C)
Gui 1: Add, Button, wp hp gPlay, % chr(0x34)
Gui 1: Add, Button, wp hp gEdit, % chr(0xA4)
if ActivateFindtext
Gui 1: Add, Button, wp hp gfindtext, % chr(0x4c)
}
Gui 1: Font, s10, Verdana
if ShowASWIIbuttons
{
Gui 1: Add, Button, wp hp Left gaswii_record, ASWII: Record
Gui 1: Add, Button, wp hp Left gaswii_get, ASWII: Get
Gui 1: Add, Button, wp hp Left gaswii_clear, ASWII: Clear
}
Gui 1: Add, CheckBox, x10 hp-25 -border gtoggleLoopPlay vLoopPlay, Loop
Gui 1: Add, Edit, xs+10 w80 h20 +Number ved_rep Disabled c5D69BA,
Gui 1: Add, UpDown, vrepeat x34 w18 h20 Range1-999999, 10
Gui 1: Font, s9, verdana
Gui 1: Add, CheckBox, -border xs+10 yp+28 w100 h35 checked%coordmousewindow% gtoggleMouseRelative vrelative, Crd Win Rel
gui 1: font, s12, webdings
if showsetupButton
Gui 1: Add, Button, xs w40 h30 gsetup, % chr(0x40)
if ShowMenuButton
Gui 1: Add, Button, xp+40 w40 h30 ghide, % chr(0x63)
if ShowExitButton
Gui 1: Add, Button, xp+40 w40 h30 vexit gExit, % chr(0x72)
Gui 2: +AlwaysOnTop Caption +ToolWindow
Gui 2: Add, CheckBox, x10 section w320 h18 checked%beepsound% -border vbeepsound goka, Emits a beep tone from the PC speaker on record
Gui 2: Add, CheckBox, xs wp hp checked%splashscreen% -border vsplashscreen goka, Display startup splash screen
Gui 2: Add, CheckBox, xs wp hp checked%displayicons% -border vdisplayicons goka, Display Icons in Menu (need restart)
Gui 2: Add, CheckBox, xs wp hp checked%ActivateFindtext% -border vActivateFindtext goka, Activate Findtext tool (need restart)
Gui 2: Add, CheckBox, xs wp hp checked%ShowASWIIbuttons% -border vShowASWIIbuttons goka, Show Auto Script Writer II buttons (need restart)
Gui 2: Add, Groupbox, xs-10 w345 h150 , Macro File
Gui 2: Add, CheckBox, xs y140 section w320 h18 checked%TooltipMessage% -border vTooltipMessage goka, Append tooltip debug messages
Gui 2: Add, CheckBox, xs ys+20 wp hp checked%AppendClass% -border vAppendClass goka, Append ClassName to window titles
Gui 2: Add, CheckBox, xs yp+20 wp hp checked%RecordasVkSc% -border vRecordasVkSc goka, Record keyboards inputs as {VkSc} code
Gui 2: Add, CheckBox, xs yp+20 wp hp checked%SplitLines% -border vSplitLines goka, Split long keyboard recording lines
Gui 2: Add, CheckBox, xs yp+20 wp hp checked%EditAfterRecord% -border vEditAfterRecord goka, Show the internal editor after the end of the recording
Gui 2: Add, CheckBox, xs yp+20 wp hp checked%CoordMouseWindow% -border vCoordMouseWindow goka, Coord Mouse relative to window
Gui 2: Add, button, xs yp+40 w100 h30 geditini, Advanced options
Gui 2: Add, button, xp+105 yp h30 greload, Reload
;--Gui 3 ---------------------------------------------------------------------------
Menu, FileMenu, Add, &New, FileNew
Menu, FileMenu, Add, &Import, FileOpen
Menu, FileMenu, Add, &Export, FileSaveAs
Menu, FileMenu, Add, &Save, FileSave
Menu, FileMenu, Add, Save and &Backup, SaveAndBackup
Menu, FileMenu, Add, &Restore Backup, RestoreBackup
Menu, FileMenu, Add, Restore &Last Record, RestoreLastRecord
Menu, FileMenu, Add, &Open External Editor, externaleditor
Menu, FileMenu, Add ; Separator line.
Menu, FileMenu, Add, E&xit, FileExit
Menu, EditMenu, Add, &Fold all blocs in a function, Fold
Menu, EditMenu, Add, &Shorten all blocs, Short
Menu, EditMenu, Add, Remove &Empty Lines, RemoveEmptyLines
Menu, EditMenu, Add, Remove T&ooltip Lines, RemoveTooltipLines
Menu, EditMenu, Add, Remove &Titles, RemoveTitleLines
Menu, EditMenu, Add, Remove Titles &Class, RemoveTitleClassLines
Menu, EditMenu, Add, Clear E&ditor, FileNew
Menu, HelpMenu, Add, &Shortcuts, Shortcuts
Menu, HelpMenu, Add, &About, HelpAbout
; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Edit, :EditMenu
Menu, MyMenuBar, Add, &Options, setup
Menu, MyMenuBar, Add, &Help, :HelpMenu
; Attach the menu bar to the window:
Gui 3: Menu, MyMenuBar
gui 3: font, s%editorfontsize%, Lucida Console
; Create the main Edit control and display the window:
Gui 3: +Resize ; Make the window resizable.
Gui 3: Add, tab,, Macro|Temp Edit
Gui 3: Add, Edit, vMainEdit -Wrap HScroll WantTab W640 h500 ;R40
CurrentFileName = ; Indicate that there is no current file.
gui 3: font, s9, Lucida Console
Gui 3: add, button, gInsertSleep , insert Sleep 200 \n
Gui 3: add, button, gInsertSleepSend , insert sleep 500 send... ; insert a sleep then a send command to break long lines of keyboard commands
Gui 3: add, button, gSaveCurrentFileb , Save and exit
gui 3: tab, 2
Gui 3: Add, Edit, vTempEditor -Wrap HScroll WantTab W640 R40
;-------------------------------------------------------------------
if (startmode=1)
{
ShowMenu:=1
Gui 1: Show, NA x0 y60 w1, Macro Record
if splashscreen
{
Progress, B1 ZH0 cw5AEC49, Unofficial Macro Recorder %ScriptVersion%
SetTimer, TimeoutTimer, -2500
}
}
if (startmode=2)
{
ShowMenu:=1
Gui 1: Show, NA x0 y60 AutoSize, Macro Record
}
if (startmode=3) ; start hidden
{
Gui 1: Show, NA x0 y60 w0, Macro Record
ShowMenu:=0
Gui 1: hide
if splashscreen
{
Progress, B1 ZH0, UMR Unofficial Macro Record %ScriptVersion%`n
SetTimer, TimeoutTimer, -2500
}
}
;--------------------------------------------------------------------------------------------------
MouseOnGui:=0
SetTimer, GuiMenuShow, 2000
OnMessage(0x200, "WM_MOUSEMOVE")
if ActivateFindtext
gosub, ftext
return
oka:
gui 2: submit, nohide
updateini(,1)
return
setup:
gui 2: show, autosize
return
editini:
run, %Ini_File%
return
reload:
reload
return
ASWII_get:
if WinExist("AutoScriptWriter II")
{
FileDelete, %LogFile%
ControlGetText, OutputVar , Edit2, AutoScriptWriter II - ( by Larry Keys )
Loop,parse,OutputVar, `n
{
cm := a_loopfield
If cm contains WinActivate
{
cm:=RegExReplace(cm,"WinActivate","`nWinActivate")
}
out .= cm . "`n"
}
outputvar:=out
out=
FileAppend, %OutputVar%, %LogFile%
;backupfile:= SubStr( LogFile, 1, -3 ) . "bak"
;FileDelete, %BackupFile%
;FileAppend, %OutputVar%, %backupfile%
Progress, B1 ZH0, Text transfered from AutoScriptWriter II`n Successfully
SetTimer, TimeoutTimer, -2000
}
return
ASWII_record:
if WinExist("AutoScriptWriter II")
{
winactivate, AutoScriptWriter II
sleep, 300
ControlFocus , Button1, AutoScriptWriter II
ControlClick , Button1, AutoScriptWriter II
}
else
{
IfWinNotExist, AutoScriptWriter II
ifexist, %AutoScriptWriterPath%
run, % AutoScriptWriterPath
WinWaitActive,,,2
ControlFocus , Button1, AutoScriptWriter II
ControlClick , Button1, AutoScriptWriter II
}
return
ASWII_clear:
if WinExist("AutoScriptWriter II")
{
ControlSetText , Edit2,, AutoScriptWriter II
}
return
Run:
Critical
Gui 1: Submit
MouseOnGui:=0
Gui 1: Show, NA x0 y60 w1
if IsLabel(s:=A_GuiControl)
Goto, %s%
return
Exit:
msgbox,33,Unofficial Macro Recorder %ScriptVersion%, Do you really want to exit?
IfMsgBox, OK
exitapp
return
GuiMenuShow:
ListLines, Off
Gui 1: +AlwaysOnTop
MouseGetPos,,, mouse_id
if (mouse_id=gui_id)!=MouseOnGui
{
if showmenu
if (MouseOnGui:=!MouseOnGui)
Gui 1: Show, NA AutoSize
else
Gui 1: Show, NA x0 y60 w1
}
SetTimer, GuiMenuShow, 2000
return
WM_MOUSEMOVE() {
ListLines, Off
global MouseOnGui
if (!MouseOnGui and A_Gui=1)
{
MouseOnGui:=1
Gui 1: Show, NA AutoSize
}
SetTimer, GuiMenuShow, 100
}
Record:
gui 3: hide
Suspend, Permit
if (Recording or Playing)
return
oldtt=
ToolTip, % " Please Wait ", 0, 0
sleep, %StartRecordDelay%
if (StartRecordDelay>=1)
if beepsound
Soundbeep
Recording:=1, IsPaused:=0, Logs:="", SetHotkey(1)
ToolTip, % " Recording ", 0, 0
SetTimer, CheckWindow, 100
return
toggleMouseRelative:
if (CoordMouseWindow:=!CoordMouseWindow)
{
guicontrol,, Relative, 1
Progress, B1 ZH0, CoordMode Window
SetTimer, TimeoutTimer, -2000
}
else
{
guicontrol,, Relative, 0
Progress, B1 ZH0, CoordMode Screen
SetTimer, TimeoutTimer, -2000
}
return
Stop:
Suspend, Permit
if Recording
{
GuiControlGet, Relative
Logs:=header
. "`nCoordMode, ToolTip"
. "`nCoordMode, Mouse, " . (Relative ? "Window":"Screen")
. "`n`n" . Trim(Logs,"`n")
. "`n" . footer
if SplitLines
Logs:=addsleepaftersend(Logs)
FileDelete, %LogFile%
FileAppend, %Logs%, %LogFile%
; save last record
LastRecordfile:= SubStr( LogFile, 1, -3 ) . "lrc"
FileDelete, %LastRecordfile%
FileAppend, %Logs%, %LastRecordfile%
------------------------------------------------------------------------------------------
SetTimer, CheckWindow, Off
ToolTip
SetHotkey(0), Logs:="", Recording:=0, IsPaused:=0
if beepsound
{
soundbeep
soundbeep
}
if EditAfterRecord
gosub, edit
return
}
LoopPlay:=0
SetTitleMatchMode, 2
DetectHiddenWindows, On
SplitPath, LogFile, FileName
WinGet, list, List, %FileName% ahk_class AutoHotkey
Loop, %list%
{
id:=list%A_Index%
if (id=A_ScriptHwnd) or !WinExist("ahk_id " id)
Continue
WinGet, pid, PID
WinClose
WinWaitClose,,, %WinWaitDelay%
if ErrorLevel
Process, Close, %pid%
}
return
toggleLoopPlay:
if (LoopPlay:=!LoopPlay)
{
guicontrol,, loopplay, 1
GuiControl,enable,ed_rep
Progress, B1 ZH0, LoopPlay enabled
SetTimer, TimeoutTimer, -2000
}
else
{
guicontrol,, loopplay, 0
GuiControl,enable0,ed_rep
Progress, B1 ZH0, LoopPlay disabled
SetTimer, TimeoutTimer, -2000
}
return
TimeoutTimer:
Progress, Off
Return
Play:
if beepsound
soundbeep
if ShowMenu
Gui 1: Show, NA x0 y60 w1
GuiControlGet,ed_rep,,repeat
if WinExist("AutoScriptWriter II")
{
WinMinimize, AutoScriptWriter II
}
Suspend, Permit
if Recording
Gosub, Stop
if !LoopPlay
GuiControlGet, LoopPlay
Playing:=1
ToolTip, % " Playing " . ed_rep , 0, 0
Critical, Off
ListLines, Off
if !ed_rep
ed_rep:=1
if !LoopPlay
ed_rep:=1
Loop % ed_rep
{
ToolTip, % " Playing " . a_index , 0, 0
RunWait, %A_AhkPath% "%LogFile%"
if !LoopPlay
Break
}
ListLines, On
ToolTip
Playing:=0
return
Edit:
Suspend, Permit
Critical, Off
gosub internaleditor
;Run, %EditorPath% "%LogFile%"
return
Pause:
Suspend, Permit
if Recording
{
IsPaused:=!IsPaused, SetHotkey(!IsPaused)
ToolTip, % IsPaused ? " Record Pause "
: " Recording ", 0, 0
return
}
SetTitleMatchMode, 2
DetectHiddenWindows, On
SplitPath, LogFile, FileName
WinGet, list, List, %FileName% ahk_class AutoHotkey
Loop, %list%
{
id:=list%A_Index%
if (id=A_ScriptHwnd) or !WinExist("ahk_id " id)
Continue
PostMessage, 0x111, 65306
}
return
;========== Function and Label ==========
SetHotkey(f=0)
{
static AllKeys, ExcludeKeys:="Pause"
ListLines, Off
if !Allkeys
{
s:="|Control|Alt|Shift||NumpadEnter|Home|End"
. "|PgUp|PgDn|Left|Right|Up|Down|Del|Ins|"
Loop, 254
k:=GetKeyName(Format("VK{:X}", A_Index))
, s.=InStr(s, "|" k "|") ? "" : k "|"
For k,v in {Control:"Ctrl", Escape:"Esc"}
s:=StrReplace(s, k, v)
AllKeys:=Trim(SubStr(s,InStr(s,"||")),"|")
}
;------------------
f:=f ? "On":"Off"
For i,k in StrSplit(AllKeys,"|")
if k not in %ExcludeKeys%
Hotkey, ~*%k%, LogKey, %f% UseErrorLevel
ListLines, On
}
LogKey:
Critical
k:=Trim(A_ThisHotkey,"~*#!+^<>$"), r:=SubStr(k,2)
if r in Win,Alt,Ctrl,Shift,Button
if IsLabel(k)
Goto, %k%
; Some input auto completion and send the left or right keys
; for the cursor center, excluding these key records
if (k="NumpadLeft" or k="NumpadRight") and !GetKeyState(k,"P")
return
if !RecordasVkSc
k:=k="``" ? "``" k : StrLen(k)>1 or k=";" ? "{" k "}" : k
if RecordasVkSc
{
if k contains %ExcludeVkSc%
k:=k="``" ? "``" k : StrLen(k)>1 or k=";" ? "{" k "}" : k
else
k:=Format("{{}vk{1:X}sc{2:X}{}}", GetKeyVK(k), GetKeySC(k))
}
Log(k,1)
return
LWin:
RWin:
LAlt:
RAlt:
LCtrl: ; Individually press LCtrl to record mouse movement
RCtrl:
LShift:
RShift:
Log("{" k " Down}",1)
Critical, Off
KeyWait, %A_ThisLabel%
Critical
k:=A_ThisLabel
Log("{" k " Up}",1)
;----------------------------
if (k="LCtrl")
and SubStr(Logs,1-22)="{LCtrl Down}{LCtrl Up}"
{
Logs:=SubStr(Logs,1-14-22,14)="`nSend, {Blind}"
? SubStr(Logs,1,-14-22) : SubStr(Logs,1,-22)
if Relative
CoordMode, Mouse, Window
MouseGetPos, X, Y
Log("MouseMove, " X ", " Y)
}
return
hide: ;enable disable menu
showmenu:=0
Gui 1: hide
Progress, B1 ZH0, Menu Disabled `nDouble Right Click or Press F6+F4
SetTimer, TimeoutTimer, -3000
return
ToggleMenu:
ShowMenu:=!ShowMenu
if ShowMenu
{
Gui 1: Show, NA AutoSize
SetTimer, GuiMenuShow, 1000
}
else
{
Gui 1: hide
Progress, B1 ZH0, Menu Disabled `nDouble Right Click or Press F6+F4
SetTimer, TimeoutTimer, -3000
}
return
LButton:
IfEqual, MouseOnGui, 1, return
RButton:
MButton:
SetTimer, CheckWindow, On
if CoordMouseWindow
{
CoordMode, Mouse, Window
winactivate
sleep, 200
MouseGetPos, zx, zy, id
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
mevent:=1
}
if !CoordMouseWindow
{
CoordMode, Mouse, Screen
winactivate
sleep, 200
MouseGetPos, msx, msy
mevent:=1
}
return
CheckWindow:
ListLines, Off
Critical
;ùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
WinGetTitle, tt, A
WinGetClass, tc, A
if (tt="" and tc="")
return
if AppendClass
tt:=SubStr(tt,1,50) . (tc ? " ahk_class " . tc:"")
if (tt=oldtt)
{
if mevent
{
if CoordMouseWindow
{
if Append_to_Click !=
apm:=Append_to_Click . "`nMouseClick, " . SubStr(k,1,1) . ", " . zx . ", " . zy ""
else
apm:="MouseClick, " . SubStr(k,1,1) . ", " . zx . ", " . zy ""
log(apm)
}
if !CoordMouseWindow
{
if Append_to_Click !=
apm:=Append_to_Click . "`nMouseClick, " . SubStr(k,1,1) . ", " . msx . ", " . msy ""
else
apm:="MouseClick, " . SubStr(k,1,1) . ", " . msx . ", " . msy ""
log(apm)
}
}
mevent:=0
return
}
oldtt:=tt
tt:=RegExReplace(Trim(tt), "[;``]", "``$0")
StringReplace, tt, tt, ", "", All
if !CoordMouseWindow
if tt contains Recording,Macro Record,Progman,Program Manager
return
IfEqual, MouseOnGui, 1, return
if TooltipMessage
{
if tt
{
tt:="ToolTip, Waiting..." tt ", 80, 0`n"
. "WinWait, " . tt . ",`n"
. "IfWinNotActive, " . tt . ", `n"
. "WinActivate, " . tt . ",`n"
. "WinWaitActive, " . tt ",, " . WinWaitDelay . "`n"
. "ToolTip" . "`n"
}
}
if !TooltipMessage
{
if tt
{
tt:="WinWait, " . tt . ",`n"
. "IfWinNotActive, " . tt . ", `n"
. "WinActivate, " . tt . ",`n"
. "WinWaitActive, " . tt ",, " . WinWaitDelay . "`n"
}
}
r:=SubStr(Logs, i:=InStr(Logs,"`ntt:=",0,0))
if (i) and !InStr(r,"Sleep")
Logs:=SubStr(Logs,1,i-1)
Log(tt)
return
Log(str="", Keyboard=0, MaxDelay=2000)
{
global Logs, LastTime, SplitLines
Delay:=(Time:=A_TickCount)-LastTime, LastTime:=Time
if !SplitLines
delay:=0
if (Keyboard and Delay<1000)
{
if SubStr(Logs,0)!="`n"
{
Logs.=str
return
}
}
if keyboard
str:="`nSend, {Blind}" . str
t:=A_TickCount, Delay:=(t-LastTime)//2, LastTime:=t
Delay:=Delay<MaxDelay ? Delay : MaxDelay
if (Logs!="")
if Append_to_Click !=
Logs:=RTrim(Logs,"`n") "`n" . Append_to_Click
else
Logs:=RTrim(Logs,"`n") . "`n"
Logs.=Keyboard ? str : "`n" . str . "`n"
}
;----------------------------------
;https://autohotkey.com/board/topic/33506-read-ini-file-in-one-go/
updateini( filename = 0, updatemode = 0 )
;
; updates From/To a whole .ini file
;
; By default the update mode is set to 0 (Read)
; and creates variables like this:
; %Section%%Key% = %value%
;
; You don't have to state the updatemode when reading, just use
;
; update(filename)