-
Notifications
You must be signed in to change notification settings - Fork 3
/
text-capture-acc.ahk
2735 lines (2426 loc) · 104 KB
/
text-capture-acc.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
; text-capture-acc.ahk - main file
;
; Charset for this file must be UTF 8 with BOM.
; it may not function properly otherwise.
;
; Script written for AHK_L v1.1.28 Unicode.
;
; Disclaimer: this script is provided "as is", without any kind of warranty.
; The author(s) shall not be liable for any damage caused by using
; this script or its derivatives, et cetera.
;
; =====================
; GENERAL OVERVIEW
; =====================
;
; Compilation directives; include files in binary and set file properties
; ===========================================================
;
;@Ahk2Exe-SetName Text-Capture-ACC
;@Ahk2Exe-SetCopyright Marius Şucan (2017-2018)
;@Ahk2Exe-SetCompanyName sucan.ro
;================================================================
; Section 0. Auto-exec.
;================================================================
; Script Initialization
#SingleInstance Force
#NoEnv
#MaxMem 128
#ClipboardTimeout 3000
DetectHiddenWindows, On
; #Warn Debug
ComObjError(false)
SetTitleMatchMode, 2
SetBatchLines, -1
ListLines, Off
SetWorkingDir, %A_ScriptDir%
Critical, On
; Default Settings
Global IniFile := "text-capture-acc.ini"
, Copy2Clip := 1
, showACCdetails := 1
; OSD settings
, DisplayTimeUser := 3 ; in seconds
, GuiX := 40
, GuiY := 250
, FontName := (A_OSVersion="WIN_XP" && FileExist(A_WinDir "\Fonts\ARIALUNI.TF")) ? "Arial Unicode MS" : "Arial"
, FontSize := 19
, PrefsLargeFonts := 0
, OSDbgrColor := "131209"
, OSDtextColor := "FFFEFA"
, OSDalpha := 230
, OSDmarginTop := 20
, OSDmarginBottom := 20
, OSDmarginSides := 25
, maxMainLength := 65
; Script's own global shortcuts (hotkeys)
, GlobalKBDhotkeys := 1 ; Enable system-wide shortcuts (hotkeys)
, KBDCapText := "Pause"
, KBDCapTextConstant := "^Pause"
, ShowPreview := 0 ; let it be a persistent setting
, ThisFile := A_ScriptName
; Release info
, Version := "0.7"
, ReleaseDate := "2020 / 06 / 27"
, ScriptInitialized, FirstRun := 1
; Check if INIT previously failed or if KP is running and then load settings.
; These functions are in Section 8.
INIaction(0, "FirstRun", "SavedSettings")
If (FirstRun=0)
{
INIsettings(0)
} Else
{
CheckSettings()
INIsettings(1)
}
; Initialization variables. Altering these may lead to undesired results.
Global Debug := 0 ; for testing purposes
, DisplayTime := DisplayTimeUser*1000
, MainGuiVisible := 0
, AccTextCaptureActive := 0
, LastMainQuoteDisplay := 1 ; timer to keep track of OSD redraws
, Tickcount_start := 0 ; timer to count repeated key presses
, MousePosition := ""
, DoNotRepeatTimer := 0
, lastMsgDisplayied := ""
, PrefOpen := 0
, FontList := []
, captureFocusedTab := A_TickCount
, LargeUIfontValue := 13
, InstKBDsWinOpen, CurrentTab, AnyWindowOpen := 0
, PreviewWindowText := "Preview " Lola "window... " Lola2
, GlobalKBDsList := "KBDCapText,KBDCapTextConstant"
, KeysComboList := "(Disabled)|(Restore Default)|[[ 0-9 / Digits ]]|[[ Letters ]]|Right|Left|Up|Down|Home|End
|Page_Down|Page_Up|Backspace|Space|Tab|Delete|Enter|Escape|Insert|CapsLock|NumLock|ScrollLock|L_Click
|M_Click|R_Click|PrintScreen|Pause|Break|CtrlBreak|AppsKey|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12
|Nav_Back|Nav_Favorites|Nav_Forward|Nav_Home|Nav_Refresh|Nav_Search|Nav_Stop|Help|Launch_App1
|Launch_App2|Launch_Mail|Launch_Media|Media_Next|Media_Play_Pause|Media_Prev|Media_Stop|Pad0|Pad1
|Pad2|Pad3|Pad4|Pad5|Pad6|Pad7|Pad8|Pad9|PadClear|PadDel|PadDiv|PadDot|PadHome|PadEnd|PadEnter
|PadIns|PadLeft|PadRight|PadAdd|PadSub|PadMult|PadPage_Down|PadPage_Up|PadUp|PadDown|Sleep
|Volume_Mute|Volume_Up|Volume_Down|WheelUp|WheelDown|WheelLeft|WheelRight|[[ VK nnn ]]|[[ SC nnn ]]"
, hMainOSD, ColorPickerHandles
, hMain := A_ScriptHwnd, uia
, CCLVO := "-E0x200 +Border -Hdr -Multi +ReadOnly Report AltSubmit gsetColors"
, BaseURL := "http://marius.sucan.ro/media/files/blog/ahk-scripts/"
, hWinMM := DllCall("kernel32\LoadLibraryW", "Str", "winmm.dll", "Ptr")
, ScriptelSuspendel := 0
, ForceUpdate := 0 ; this will be used when major changes require full update
; Initializations of the core components and functionality
uia := UIA_Interface()
Sleep, 5
CreateGlobalShortcuts()
InitializeTray()
hCursM := DllCall("user32\LoadCursorW", "Ptr", NULL, "Int", 32646, "Ptr") ; IDC_SIZEALL
hCursH := DllCall("user32\LoadCursorW", "Ptr", NULL, "Int", 32649, "Ptr") ; IDC_HAND
OnMessage(0x404, "AHK_NOTIFYICON")
OnMessage(0x200, "MouseMove") ; WM_MOUSEMOVE
Sleep, 5
ScriptInitialized := 1 ; the end of the autoexec section and INIT
Return
;================================================================
; Section 1. The OSD GUI - CreateOSDGUI()
; - GetTextExtentPoint() and GuiGetSize() are constantly used
; to determine text and window sizes.
;================================================================
stripText(txt) {
StringReplace, txt, txt, %A_SPACE%%A_SPACE%, %A_SPACE%, All
StringReplace, txt, txt, `r`n, %A_Space%, All
StringReplace, txt, txt, `n, %A_Space%, All
StringReplace, txt, txt, `r, %A_Space%, All
StringReplace, txt, txt, `f, %A_Space%, All
StringReplace, txt, txt, %A_TAB%, %A_SPACE%, All
StringReplace, txt, txt, %A_SPACE%%A_SPACE%, %A_SPACE%, All
txt := RegExReplace(txt, "\s+", A_Space)
If (txt=A_Space)
txt := ""
Return txt
}
CreateMainGUI(msg2Display) {
Critical, On
msg2Display := stripText(msg2Display)
If msg2Display
lastMsgDisplayied := msg2Display
Else
Return
msg2Display := ST_wordWrap(msg2Display, maxMainLength)
msg2Display := ST_LineWrap(msg2Display, maxMainLength+1)
Gui, MainGui: Destroy
Sleep, 25
If (PrefOpen=0)
Global LastMainQuoteDisplay := A_TickCount
HorizontalMargins := OSDmarginTop
Gui, MainGui: -DPIScale -Caption +Owner +ToolWindow +HwndhMainOSD
Gui, MainGui: Margin, %OSDmarginSides%, %HorizontalMargins%
Gui, MainGui: Color, %OSDbgrColor%
If (FontChangedTimes>190)
Gui, MainGui: Font, c%OSDtextColor% s%FontSize% Bold,
Else
Gui, MainGui: Font, c%OSDtextColor% s%FontSize% Bold, %FontName%
Gui, MainGui: Add, Text, hwndhMainTxt, %msg2Display%
Gui, MainGui: Show, NoActivate AutoSize x%GuiX% y%GuiY%, MainWin
WinSet, Transparent, %OSDalpha%, MainWin
WinSet, AlwaysOnTop, On, MainWin
MainGuiVisible := 1
quoteDisplayTime := (PrefOpen=1) ? DisplayTime*1.5 : StrLen(msg2Display) * 100 + 1000
If (PrefOpen!=1)
SetTimer, DestroyMainGui, % -quoteDisplayTime
}
ST_LineWrap(string, column= 56, indentChar= "") {
; String Things - Common String & Array Functions, 2014
; by tidbit https://autohotkey.com/board/topic/90972-string-things-common-text-and-array-functions/
CharLength := StrLen(indentChar)
, columnSpan := column - CharLength
, Ptr := A_PtrSize ? "Ptr" : "UInt"
, NewLineType := A_IsUnicode ? "UShort" : "UChar"
, UnicodeModifier := A_IsUnicode ? 2 : 1
, VarSetCapacity(out, (StrLen(string) + (Ceil(StrLen(string) / columnSpan) * (column + CharLength + 1))) * UnicodeModifier, 0)
, A := &out
loop, parse, string, `n, `r
If ((FieldLength := StrLen(ALoopField := A_LoopField)) > column)
{
DllCall("RtlMoveMemory", Ptr, A, Ptr, &ALoopField, "UInt", column * UnicodeModifier)
, A += column * UnicodeModifier
, NumPut(10, A+0, 0, NewLineType)
, A += UnicodeModifier
, Pos := column
While (Pos < FieldLength)
{
If CharLength
DllCall("RtlMoveMemory", Ptr, A, Ptr, &indentChar, "UInt", CharLength * UnicodeModifier)
, A += CharLength * UnicodeModifier
If (Pos + columnSpan > FieldLength)
DllCall("RtlMoveMemory", Ptr, A, Ptr, &ALoopField + (Pos * UnicodeModifier), "UInt", (FieldLength - Pos) * UnicodeModifier)
, A += (FieldLength - Pos) * UnicodeModifier
, Pos += FieldLength - Pos
Else
DllCall("RtlMoveMemory", Ptr, A, Ptr, &ALoopField + (Pos * UnicodeModifier), "UInt", columnSpan * UnicodeModifier)
, A += columnSpan * UnicodeModifier
, Pos += columnSpan
NumPut(10, A+0, 0, NewLineType)
, A += UnicodeModifier
}
} Else
DllCall("RtlMoveMemory", Ptr, A, Ptr, &ALoopField, "UInt", FieldLength * UnicodeModifier)
, A += FieldLength * UnicodeModifier
, NumPut(10, A+0, 0, NewLineType)
, A += UnicodeModifier
VarSetCapacity(out, -1)
Return SubStr(out,1, -1)
}
ST_wordWrap(string, column=56, indentChar="") {
; String Things - Common String & Array Functions, 2014
; by tidbit https://autohotkey.com/board/topic/90972-string-things-common-text-and-array-functions/
; fixed by Marius Șucan, such that it does not give Continuable Exception Error on some systems
indentLength := StrLen(indentChar)
Loop, Parse, string, `n
{
If (StrLen(A_LoopField) > column)
{
pose := 1
Loop, Parse, A_LoopField, %A_Space%
{
loopLength := StrLen(A_LoopField)
If (pose + loopLength <= column)
{
out .= (A_Index = 1 ? "" : " ") A_LoopField
pose += loopLength + 1
} Else
{
pose := loopLength + 1 + indentLength
out .= "`n" indentChar A_LoopField
}
}
out .= "`n"
} Else
out .= A_LoopField "`n"
}
result := SubStr(out, 1, -1)
Return result
}
DestroyMainGui() {
Gui, MainGui: Destroy
MainGuiVisible := 0
}
MouseMove(wP, lP, msg, hwnd) {
; Function by Drugwash
Global
Local A
SetFormat, Integer, H
hwnd+=0, A := WinExist("A"), hwnd .= "", A .= ""
SetFormat, Integer, D
If InStr(hMainOSD, hwnd) && (A_TickCount - LastMainQuoteDisplay>700) && (A_TimeIdle<200)
{
If (PrefOpen=0)
DestroyMainGui()
DllCall("user32\SetCursor", "Ptr", hCursM)
If !(wP&0x13) ; no LMR mouse button is down, we hover
{
If A not in %hMainOSD%
hAWin := A
} Else If (wP&0x1) ; L mouse button is down, we're dragging
{
SetTimer, DestroyMainGui, Off
While GetKeyState("LButton", "P")
{
PostMessage, 0xA1, 2,,, ahk_id %hMainOSD%
DllCall("user32\SetCursor", "Ptr", hCursM)
}
SetTimer, trackMouseDragging, -1
Sleep, 0
} Else If ((wP&0x2) || (wP&0x10))
DestroyMainGui()
} Else If ColorPickerHandles
{
If hwnd in %ColorPickerHandles%
DllCall("user32\SetCursor", "Ptr", hCursH)
}
}
trackMouseDragging() {
; Function by Drugwash
Global
WinGetPos, NewX, NewY,,, ahk_id %hMainOSD%
GuiX := !NewX ? "2" : NewX
GuiY := !NewY ? "2" : NewY
If hAWin
{
If hAWin not in %hMainOSD%
WinActivate, ahk_id %hAWin%
}
saveGuiPositions()
}
saveGuiPositions() {
; function called after dragging the OSD to a new position
If (PrefOpen=0)
{
Sleep, 700
SetTimer, DestroyMainGui, -1500
INIaction(1, "GuiX", "OSDprefs")
INIaction(1, "GuiY", "OSDprefs")
} Else If (PrefOpen=1)
{
GuiControl, SettingsGUIA:, GuiX, %GuiX%
GuiControl, SettingsGUIA:, GuiY, %GuiY%
}
}
;================================================================
; Section 5. features invoked by keyboard shortcuts
; - The hotkeys registered replace the system default
;================================================================
RegisterGlobalShortcuts(HotKate,destination,apriori) {
testHotKate := RegExReplace(HotKate, "i)^(\!|\^|\#|\+)$", "")
If (InStr(HotKate, "disa") || StrLen(HotKate)<1)
{
HotKate := "(Disabled)"
Return HotKate
}
If (GlobalKBDsNoIntercept=1 || InStr(HotKate, "button"))
{
HotKate := "~" HotKate
apriori := "~" apriori
}
Hotkey, %HotKate%, %destination%, UseErrorLevel
If (ErrorLevel!=0)
{
Hotkey, %apriori%, %destination%, UseErrorLevel
Return apriori
}
Return HotKate
}
CreateGlobalShortcuts() {
If (GlobalKBDhotkeys=1)
{
KBDCapText := RegisterGlobalShortcuts(KBDCapText,"AccCaptureTextNow", "Pause")
KBDCapTextConstant := RegisterGlobalShortcuts(KBDCapTextConstant,"ToggleAccCaptureText", "^Pause")
}
}
SuspendScriptNow() {
SuspendScript(0)
}
SuspendScript(partially:=0) {
Suspend, Permit
Thread, Priority, 150
Critical, On
If (SecondaryTypingMode=1)
Return
If (PrefOpen=1 && A_IsSuspended=1)
{
SoundBeep, 300, 900
Return
}
If (AccTextCaptureActive=1)
ToggleAccCaptureText()
Sleep, 50
Menu, Tray, UseErrorLevel
Menu, Tray, Rename, &Text Capture ACC activated,&Text Capture ACC deactivated
If (ErrorLevel=1)
{
Menu, Tray, Rename, &Text Capture ACC deactivated,&Text Capture ACC activated
Menu, Tray, Check, &Text Capture ACC activated
}
Menu, Tray, Uncheck, &Text Capture ACC deactivated
friendlyName := A_IsSuspended ? "activated" : "deactivated"
CreateMainGUI("Text Capture ACC " friendlyName)
Suspend
}
AccCaptureTextNow() {
Static lastInvoked := 1, timesInvoked := 0, prevLastMsgDisplayied
If (InStr(KBDCapText, "Button") && A_TimeIdle<1200 && MainGuiVisible=0 && AccTextCaptureActive=0)
{
SetTimer, AccCaptureTextNow, -1500
Return
}
If (A_TickCount - lastInvoked < 400) && (timesInvoked>1)
|| (A_TickCount - lastInvoked < 400) && (AccTextCaptureActive=1)
{
SoundBeep
ToggleAccCaptureText()
timesInvoked := 0
Return
}
If (A_TickCount - lastInvoked < 400) ;
{
iF (prevLastMsgDisplayied=lastMsgDisplayied && StrLen(lastMsgDisplayied)>1) && (A_TickCount - DoNotRepeatTimer > 200)
{
SoundBeep
Clipboard := lastMsgDisplayied
}
timesInvoked++
Return
}
Global DoNotRepeatTimer := A_TickCount
GetAccInfo(1)
prevLastMsgDisplayied := lastMsgDisplayied
lastInvoked := A_TickCount
}
ReloadScriptNow() {
ReloadScript(0)
}
;================================================================
; Section 6. Tray menu and related functions.
;================================================================
InitializeTray() {
Menu, PrefsMenu, Add, &Customize, ShowOSDsettings
Menu, PrefsMenu, Add
Menu, PrefsMenu, Add, L&arge UI fonts, ToggleLargeFonts
Menu, PrefsMenu, Add, R&un in Admin Mode, RunAdminMode
Menu, PrefsMenu, Add
If A_IsAdmin
{
Menu, PrefsMenu, Check, R&un in Admin Mode
Menu, PrefsMenu, Disable, R&un in Admin Mode
}
If (PrefsLargeFonts=1)
Menu, PrefsMenu, Check, L&arge UI fonts
RunType := A_IsCompiled ? "" : " [script]"
Menu, Tray, NoStandard
Menu, Tray, Add, &Preferences, :PrefsMenu
Menu, Tray, Add
Menu, Tray, Add, Mouse text collector, ToggleAccCaptureText
Menu, Tray, Add
Menu, Tray, Add, &Text Capture ACC activated, SuspendScriptNow
Menu, Tray, Check, &Text Capture ACC activated
Menu, Tray, Add, &Restart, ReloadScriptNow
Menu, Tray, Add
Menu, Tray, Add, &About, AboutWindow
Menu, Tray, Add
Menu, Tray, Add, E&xit, KillScript, P50
Menu, Tray, Tip, Text Capture ACC v%Version%%RunType%
Menu, Tray, Default, Mouse text collector
}
AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd) {
Critical, off
Static lastInvoked := 1
If (PrefOpen=1 || AccTextCaptureActive=1 || A_IsSuspended || NeverDisplayOSD=1)
|| (A_TickCount - lastInvoked < 900)
Return
CreateMainGUI("Text capture tray icon")
lastInvoked := A_TickCount
}
ToggleAccCaptureText() {
AccTextCaptureActive := !AccTextCaptureActive
Menu, Tray, % (AccTextCaptureActive=0 ? "Uncheck" : "Check"), Mouse text collector
If (AccTextCaptureActive=1)
{
CreateMainGUI("Text Capture activated")
SoundBeep , 900, 100
SetTimer, GetAccInfo, 200, 50
} Else
{
SetTimer, GetAccInfo, off
CreateMainGUI("Text Capture deactivated")
SoundBeep , 300, 100
}
Sleep, 700
}
ToggleLargeFonts() {
PrefsLargeFonts := !PrefsLargeFonts
INIaction(1, "PrefsLargeFonts", "SavedSettings")
Menu, PrefsMenu, % (PrefsLargeFonts=0 ? "Uncheck" : "Check"), L&arge UI fonts
Sleep, 200
}
ReloadScript(silent:=1) {
Thread, Priority, 50
Critical, On
If (PrefOpen=1)
{
CloseSettings()
Return
}
If FileExist(ThisFile)
{
Cleanup()
Reload
Sleep, 50
ExitApp
} Else
{
CreateMainGUI("FATAL ERROR: Main file missing. Execution terminated.")
SoundBeep
Sleep, 2000
Cleanup() ; if you don't do it HERE you're not doing it right, Run %i% will force the script to close before cleanup
MsgBox, 4,, Do you want to choose another file to execute?
IfMsgBox, Yes
{
FileSelectFile, i, 2, %A_ScriptDir%\%A_ScriptName%, Select a different script to load, AutoHotkey script (*.ahk; *.ah1u)
If !InStr(FileExist(i), "D") ; we can't run a folder, we need to run a script
Run, %i%
} Else (Sleep, 500)
ExitApp
}
}
RunAdminMode() {
If !A_IsAdmin
{
Try {
Cleanup()
If A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
Else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
ExitApp
}
}
}
DeleteSettings() {
MsgBox, 4,, Are you sure you want to delete the stored settings?
IfMsgBox, Yes
{
FileSetAttrib, -R, %IniFile%
FileDelete, %IniFile%
Cleanup()
Reload
}
}
KillScript(showMSG:=1) {
Thread, Priority, 50
Critical, On
If (ScriptInitialized!=1)
ExitApp
PrefOpen := 0
If (FileExist(ThisFile) && showMSG)
{
INIsettings(1)
CreateMainGUI("Bye byeee :-)")
Sleep, 350
} Else If showMSG
{
CreateMainGUI("Adiiooosss :-(((")
Sleep, 950
}
Cleanup()
ExitApp
}
;================================================================
; Section 7. Settings window.
; - In this section you can find each preferences window
; or any other window based on SettingsGUI() and
; various functions used in the UI.
;================================================================
SettingsGUI() {
Global
Gui, SettingsGUIA: Destroy
Sleep, 15
Gui, SettingsGUIA: Default
Gui, SettingsGUIA: -MaximizeBox
Gui, SettingsGUIA: -MinimizeBox
Gui, SettingsGUIA: Margin, 15, 15
}
initSettingsWindow() {
Global ApplySettingsBTN
If (PrefOpen=1)
{
SoundBeep, 300, 900
doNotOpen := 1
Return doNotOpen
}
If (A_IsSuspended!=1)
SuspendScript(1)
PrefOpen := 1
SettingsGUI()
}
SwitchPreferences(forceReopenSame:=0) {
testPrefWind := (forceReopenSame=1) ? "lol" : CurrentPrefWindow
GuiControlGet, CurrentPrefWindow
If (testPrefWind=CurrentPrefWindow)
Return
PrefOpen := 0
GuiControlGet, ApplySettingsBTN, Enabled
Gui, Submit
Gui, SettingsGUIA: Destroy
Sleep, 25
SettingsGUI()
CheckSettings()
If (CurrentPrefWindow=5)
{
ShowOSDsettings()
VerifyOsdOptions(ApplySettingsBTN)
}
}
ApplySettings() {
Gui, SettingsGUIA: Submit, NoHide
CheckSettings()
PrefOpen := 0
INIsettings(1)
Sleep, 100
ReloadScript()
}
CloseWindow() {
AnyWindowOpen := 0
Gui, SettingsGUIA: Destroy
}
CloseSettings() {
GuiControlGet, ApplySettingsBTN, Enabled
GuiControlGet, CurrentTab
PrefOpen := 0
CloseWindow()
If (ApplySettingsBTN=0)
{
Sleep, 25
SuspendScript()
Return
}
Sleep, 100
ReloadScript()
}
SettingsGUIAGuiEscape:
If (PrefOpen=1)
CloseSettings()
Else
CloseWindow()
Return
SettingsGUIAGuiClose:
If (PrefOpen=1)
CloseSettings()
Else
CloseWindow()
Return
AddKBDmods(HotKate, HotKateRaw) {
Global
modBtnWidth := (PrefsLargeFonts=1) ? 45 : 32
reused := "x+0 +0x1000 w" modBtnWidth " hp gGenerateHotkeyStrS "
C%HotKate% := InStr(HotKateRaw, "^")
S%HotKate% := InStr(HotKateRaw, "+")
A%HotKate% := InStr(HotKateRaw, "!")
W%HotKate% := InStr(HotKateRaw, "#")
Gui, Add, Checkbox, % reused " Checked" C%HotKate% " vCtrl" HotKate, Ctrl
Gui, Add, Checkbox, % reused " Checked" A%HotKate% " vAlt" HotKate, Alt
Gui, Add, Checkbox, % reused " Checked" S%HotKate% " vShift" HotKate, Shift
Gui, Add, Checkbox, % reused " Checked" W%HotKate% " vWin" HotKate, Win
}
AddKBDcombo(HotKate, HotKateRaw) {
Global
col2width := (PrefsLargeFonts=1) ? 140 : 90
ComboChoice := ProcessChoiceKBD(HotKateRaw)
Gui, Add, ComboBox, % "x+0 w"col2width " gProcessComboKBD vCombo" HotKate, %KeysComboList%|%ComboChoice%||
}
GenerateHotkeyStrS(enableApply:=1) {
GuiControlGet, ApplySettingsBTN
kW1 := "disa"
kW2 := "resto"
kWa := "(Disabled)"
kWb := "(Restore Default)"
Loop, Parse, GlobalKBDsList, CSV
{
GuiControlGet, Combo%A_LoopField%
GuiControlGet, Ctrl%A_LoopField%
GuiControlGet, Shift%A_LoopField%
GuiControlGet, Alt%A_LoopField%
GuiControlGet, Win%A_LoopField%
%A_LoopField% := ""
%A_LoopField% .= Ctrl%A_LoopField%=1 ? "^" : ""
%A_LoopField% .= Shift%A_LoopField%=1 ? "+" : ""
%A_LoopField% .= Alt%A_LoopField%=1 ? "!" : ""
%A_LoopField% .= Win%A_LoopField%=1 ? "#" : ""
%A_LoopField% .= ProcessChoiceKBD2(Combo%A_LoopField%)
If InStr(Combo%A_LoopField%, kW1)
%A_LoopField% := kWa
If InStr(Combo%A_LoopField%, kW2)
%A_LoopField% := kWb
}
keywords := "i)(disa|resto)"
KBDsTestDuplicate := KBDCapText "&" KBDCapTextConstant
For each, kbd2test in StrSplit(KBDsTestDuplicate, "&")
{
countDuplicate := 0
Loop, Parse, KBDsTestDuplicate, &
{
If RegExMatch(A_LoopField, keywords)
Continue
If (kbd2test=A_LoopField)
countDuplicate++
}
If (countDuplicate>1)
disableButtons := 1
}
If (disableButtons=1)
{
ToolTip, Detected duplicate keyboard shorcuts...
SoundBeep, 300, 900
GuiControl, Disable, ApplySettingsBTN
GuiControl, Disable, CurrentPrefWindow
GuiControl, Disable, CancelBTN
SetTimer, DupeHotkeysToolTipDummy, -1500
} Else
{
GuiControl, % (!enableApply ? "Disable" : "Enable"), ApplySettingsBTN
GuiControl, Enable, CurrentPrefWindow
GuiControl, Enable, CancelBTN
}
}
DupeHotkeysToolTipDummy() {
ToolTip
}
ProcessComboKBD(enableApply:=1) {
forbiddenChars := "(\~|\*|\!|\+|\^|\#|\$|\<|\>|\&)"
keywords := "i)(\(.|^([\p{Z}\p{P}\p{S}\p{C}\p{N}].)|disa|resto|\s|\[\[|\]\])"
GuiControlGet, activeCtrl, FocusV
Loop, Parse, GlobalKBDsList, CSV
{
GuiControlGet, CbEdit%A_LoopField%,, Combo%A_LoopField%
If RegExMatch(CbEdit%A_LoopField%, forbiddenChars)
GuiControl,, Combo%A_LoopField%, | %KeysComboList%
If RegExMatch(CbEdit%A_LoopField%, keywords)
SwitchStateKBDbtn(A_LoopField, 0, 0)
}
StringReplace, activeCtrl, activeCtrl, ComboK, K
If (RegExMatch(CbEdit%activeCtrl%, keywords) || StrLen(CbEdit%activeCtrl%)<1)
SwitchStateKBDbtn(activeCtrl, 0, 0)
Else
SwitchStateKBDbtn(activeCtrl, 1, 0)
GuiControl, % (!enableApply ? "Disable" : "Enable"), ApplySettingsBTN
GenerateHotkeyStrS(enableApply)
}
ProcessChoiceKBD(strg) {
Loop, Parse, % "^~#&!+<>$*"
StringReplace, strg, strg, %A_LoopField%
If !strg
strg := "(Disabled)"
Return strg
}
ProcessChoiceKBD2(strg) {
StringReplace, strg, strg,Pad,Numpad
StringReplace, strg, strg,Page_Up,PgUp
StringReplace, strg, strg,Page_Down,PgDn
StringReplace, strg, strg,Nav_,Browser_
StringReplace, strg, strg,_Click,Button
StringReplace, strg, strg,numnumpad,Numpad
Return strg
}
SwitchStateKBDbtn(HotKate, do, noCombo:=1) {
action := (do=0) ? "Disable" : "Enable"
If (noCombo=1)
GuiControl, %action%, Combo%HotKate%
GuiControl, %action%, Ctrl%HotKate%
GuiControl, %action%, Shift%HotKate%
GuiControl, %action%, Alt%HotKate%
GuiControl, %action%, Win%HotKate%
}
hexRGB(c) {
; unknown source
r := ((c&255)<<16)+(c&65280)+((c&0xFF0000)>>16)
c := "000000"
DllCall("msvcrt\sprintf", "AStr", c, "AStr", "%06X", "UInt", r, "CDecl")
Return c
}
Dlg_Color(Color,hwnd) {
; Function by maestrith
; from: [AHK 1.1] Font and Color Dialogs
; https://autohotkey.com/board/topic/94083-ahk-11-font-and-color-dialogs/
; Modified by Marius Șucan and Drugwash
Static
If !cpdInit {
VarSetCapacity(CUSTOM,64,0), cpdInit:=1, size:=VarSetCapacity(CHOOSECOLOR,9*A_PtrSize,0)
}
Color := "0x" hexRGB(InStr(Color, "0x") ? Color : Color ? "0x" Color : 0x0)
NumPut(size,CHOOSECOLOR,0,"UInt"),NumPut(hwnd,CHOOSECOLOR,A_PtrSize,"Ptr")
,NumPut(Color,CHOOSECOLOR,3*A_PtrSize,"UInt"),NumPut(3,CHOOSECOLOR,5*A_PtrSize,"UInt")
,NumPut(&CUSTOM,CHOOSECOLOR,4*A_PtrSize,"Ptr")
If !ret := DllCall("comdlg32\ChooseColorW","Ptr",&CHOOSECOLOR,"UInt")
Exit
SetFormat, Integer, H
Color := NumGet(CHOOSECOLOR,3*A_PtrSize,"UInt")
SetFormat, Integer, D
Return Color
}
setColors(hC, event, c, err=0) {
; Function by Drugwash
; Critical MUST be disabled below! If that's not done, script will enter a deadlock !
Static
oc := A_IsCritical
Critical, Off
If (event != "Normal")
Return
g := A_Gui, ctrl := A_GuiControl
r := %ctrl% := hexRGB(Dlg_Color(%ctrl%, hC))
Critical, %oc%
GuiControl, %g%:+Background%r%, %ctrl%
GuiControl, Enable, ApplySettingsBTN
Sleep, 100
OSDpreview()
}
UpdateFntNow() {
Global
Fnt_DeleteFont(hfont)
fntOptions := "s" FontSize " Bold Q5"
hFont := Fnt_CreateFont(FontName,fntOptions)
; Fnt_SetFont(hOSDctrl,hfont,true)
Fnt_SetFont(hMainTxt,hfont,true)
}
OSDpreview() {
Static LastBorderState, lastFnt := FontName
Gui, SettingsGUIA: Submit, NoHide
If (ShowPreview=0)
{
DestroyMainGui()
Return
}
CreateMainGUI(PreviewWindowText)
Sleep, 25
If (lastFnt!=FontName)
{
FontChangedTimes++
lastFnt := FontName
}
; ToolTip, nr. %FontChangedTimes%
If (FontChangedTimes>190)
UpdateFntNow()
}
editsOSDwin() {
If (A_TickCount-DoNotRepeatTimer<1000)
Return
VerifyOsdOptions()
}
ShowOSDsettings() {
doNotOpen := initSettingsWindow()
If (doNotOpen=1)
Return
Global CurrentPrefWindow := 5
Global DoNotRepeatTimer := A_TickCount
Global positionB, editF1, editF2, editF3, editF4, editF5, editF6, Btn1, editF60
, editF7, editF8, editF9, editF10, editF11, editF13, editF35, editF36, editF37, Btn2
columnBpos1 := columnBpos2 := 125
KBDcol1width := 290
editFieldWid := 220
If (PrefsLargeFonts=1)
{
Gui, Font, s%LargeUIfontValue%
editFieldWid := 285
KBDcol1width := 430
columnBpos1 := columnBpos2 := columnBpos2 + 125
}
columnBpos1b := columnBpos1 + 70
Gui, Add, Tab3,, General|OSD options
Gui, Tab, 1 ; general
Gui, Add, Checkbox, x+15 y+15 gVerifyOsdOptions Checked%Copy2Clip% vCopy2Clip, Copy to clipboard the text `n (applies only when text is captured only once)
Gui, Add, Checkbox, y+10 Section gVerifyOsdOptions Checked%showACCdetails% vshowACCdetails, Show extensive ACC details
Gui, Add, Checkbox, y+10 gVerifyOsdOptions Checked%GlobalKBDhotkeys% vGlobalKBDhotkeys, Global keyboard shortcuts
Gui, Add, Text, xs+15 y+5 w%KBDcol1width%, Capture text only once
Gui, Add, Text, xs+50 y+1 w100,
AddKBDcombo("KBDCapText", KBDCapText)
AddKBDmods("KBDCapText", KBDCapText)
Gui, Add, Text, xs+15 y+1 w%KBDcol1width%, Constantly capture text
Gui, Add, Text, xs+50 y+1 w100,
AddKBDcombo("KBDCapTextConstant", KBDCapTextConstant)
AddKBDmods("KBDCapTextConstant", KBDCapTextConstant)
Gui, Tab, 2 ; size/position
Gui, Add, Text, x+15 y+15 Section, OSD position (x, y)
Gui, Add, Edit, xs+%columnBpos2% ys w65 geditsOSDwin r1 limit4 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF1, %GuiX%
Gui, Add, UpDown, vGuiX gVerifyOsdOptions 0x80 Range-9995-9998, %GuiX%
Gui, Add, Edit, x+5 w65 geditsOSDwin r1 limit4 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF2, %GuiY%
Gui, Add, UpDown, vGuiY gVerifyOsdOptions 0x80 Range-9995-9998, %GuiY%
Gui, Add, Text, xm+15 ys+30 Section, Margins (horizontal, vertical)
Gui, Add, Edit, xs+%columnBpos2% ys+0 Section w65 geditsOSDwin r1 limit3 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF11, %OSDmarginTop%
Gui, Add, UpDown, gVerifyOsdOptions vOSDmarginTop Range1-900, %OSDmarginTop%
Gui, Add, Edit, x+5 w65 geditsOSDwin r1 limit3 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF13, %OSDmarginSides%
Gui, Add, UpDown, gVerifyOsdOptions vOSDmarginSides Range1-900, %OSDmarginSides%
Gui, Add, Text, xm+15 y+10 Section, Font name
Gui, Add, Text, xs yp+30, OSD colors and opacity
Gui, Add, Text, xs yp+30, Font size
Gui, Add, Text, xs yp+30, Display time (in sec.)
Gui, Add, Text, xs yp+30, Maximum line length
Gui, Add, DropDownList, xs+%columnBpos2% ys+0 section w205 gVerifyOsdOptions Sort Choose1 vFontName, %FontName%
Gui, Add, ListView, xp+0 yp+30 w55 h25 %CCLVO% Background%OSDtextColor% vOSDtextColor hwndhLV1,
Gui, Add, ListView, x+5 yp w55 h25 %CCLVO% Background%OSDbgrColor% vOSDbgrColor hwndhLV2,
Gui, Add, Edit, x+5 yp+0 w55 hp geditsOSDwin r1 limit3 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF10, %OSDalpha%
Gui, Add, UpDown, vOSDalpha gVerifyOsdOptions Range25-250, %OSDalpha%
Gui, Add, Edit, xp-120 yp+30 w55 geditsOSDwin r1 limit3 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF5, %FontSize%
Gui, Add, UpDown, gVerifyOsdOptions vFontSize Range12-295, %FontSize%
Gui, Add, Edit, xp+0 yp+30 w55 hp geditsOSDwin r1 limit2 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF6, %DisplayTimeUser%
Gui, Add, UpDown, vDisplayTimeUser gVerifyOsdOptions Range1-99, %DisplayTimeUser%
Gui, Add, Edit, xp+0 yp+30 w55 hp geditsOSDwin r1 limit3 -multi number -wantCtrlA -wantReturn -wantTab -wrap veditF60, %maxMainLength%
Gui, Add, UpDown, vmaxMainLength gVerifyOsdOptions Range10-130, %maxMainLength%
If !FontList._NewEnum()[k, v]
{
Fnt_GetListOfFonts()
FontList := trimArray(FontList)