-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathkeypress-osd.ahk
11593 lines (10506 loc) · 408 KB
/
keypress-osd.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
; KeypressOSD.ahk - main file
; Latest version at:
; https://github.com/marius-sucan/KeyPress-OSD
; http://marius.sucan.ro/media/files/blog/ahk-scripts/keypress-osd.ahk
;
; Charset for this file must be UTF 8 with BOM.
; it may not function properly otherwise.
;
; Script written for AHK_H / AHK_L v1.1.28 Unicode.
; For compatibility with AHK_L remove the call to
; the function addScript() or ahkThread_Free().
;--------------------------------------------------------------------------------------------------------------------------
;
; Change log file:
; keypress-osd-changelog.txt
; http://marius.sucan.ro/media/files/blog/ahk-scripts/keypress-osd-changelog.txt
;
; 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
; =====================
;
; I learned coding with this project. Therefore, throughout
; the code you'll probably notice the lack of programming skills
; and good coding practices. However, I did my best to do it
; as intelligble as possible.
;
; The script is organized into sections, grouped mainly by
; functionality. Some functions borrowed from other people are all
; grouped into Section 9. In each section you can find
; additional details. Beyond this, I have been told the code
; is poorly structured, lacks a consistent coding style, and others .
; The script runs on both, AHK_H and AHK_L. To enable compatibility
; with AHK_L, the line with addScript("ahkThread_Free(deleteME)",0)
; must be deleted or commented. When it runs with AHK_L,
; many features will deactivated, because it has no support for
; threads.
;
; The ANSI versions of AHK are unsupported due to the nature and
; intended use of this script.
;
; This script file can be executed alone, without any additional files.
; It will attempt to download the auxiliary files. To avoid this, please
; set DownloadExternalFiles to 0.
;
; When the script first initializes, it saves the default
; settings in an INI file, then it attempts to identify all
; the keyboard layouts installed and gather details about
; each: name, ID, list of dead keys, and others. See
; function initLangFile().
;
; At every start, KP goes through all the Virtual Key codes
; and tests with ToUnicodeEx() and GetKeyName() if there is
; something to bind to (a key name) - this happens in
; CreateHotkey(). Afterwards, it loads from the
; language file the list of dead keys and their names
; according to the current detected keyboard layout [if
; this is enabled]. See function IdentifyKBDlayout(). The
; list of VKs for dead keys is used to distinctively bind
; to these and to display their symbols. One cannot use
; ToUnicodeEx() to display the name each time such a key is
; pressed, because it renders unusable the dead key in host apps.
;
; The main typing mode hooks to each key using the Hotkey,
; by Virtual Key (VK) and different modifiers. For the
; Shift and AltGr key combinations, the script binds
; distinctively, because it must be able to catch these
; keys orderly and always be able to determine what key
; name to display using ToUnicodeEx(). If it would bind
; simply with the (*) wildcard, dead keys cease to function
; and on slow systems, modifier detection becomes
; unreliable. By binding specifically to each modifier and
; key, based on the prefixes from the built-in variable
; %A_THISHOTKEY%, the script can properly determine what to display.
;
; When alternative hooks are enabled, a different thread
; runs with a Loop for an Input command limited to one
; character. The Input command is able to capture dead keys
; combinations (accented letters). For each key pressed, the
; resulted character is assigned to the main thread in the
; ExternalKeyStrokeRecvd variable. What this secondary thread
; sends is used only after a dead key was pressed. Therefore,
; the script still relies on the Hotkey commands and
; ToUnicodeEx(). When the layout is supported, but it has
; no dead keys, this secondary thread is never initialized.
;
; When alternate typing mode is invoked, A new
; window is created and focused in SwitchSecondaryTypingMode(),
; to capture keys with two OnMessages hooked to WM_CHAR and
; WM_DEADCHAR. KP no longer relies on the Hotkey and Input
; commands from the secondary thread. When the user hits
; Enter, the script attempts to focus the previously active
; window [by ID] and using SendInput, the text is sent.
;
; Compilation directives; include files in binary and set file properties
; ===========================================================
;
;@Ahk2Exe-AddResource WAVE sounds\caps.wav
;@Ahk2Exe-AddResource WAVE sounds\clickM.wav
;@Ahk2Exe-AddResource WAVE sounds\clickR.wav
;@Ahk2Exe-AddResource WAVE sounds\clicks.wav
;@Ahk2Exe-AddResource WAVE sounds\cups.wav
;@Ahk2Exe-AddResource WAVE sounds\deadkeys.wav
;@Ahk2Exe-AddResource WAVE sounds\firedkey.wav
;@Ahk2Exe-AddResource WAVE sounds\functionKeys.wav
;@Ahk2Exe-AddResource WAVE sounds\holdingKeys.wav
;@Ahk2Exe-AddResource WAVE sounds\keys.wav
;@Ahk2Exe-AddResource WAVE sounds\media.wav
;@Ahk2Exe-AddResource WAVE sounds\modfiredkey.wav
;@Ahk2Exe-AddResource WAVE sounds\mods.wav
;@Ahk2Exe-AddResource WAVE sounds\num0pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num1pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num2pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num3pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num4pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num5pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num6pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num7pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num8pad.wav
;@Ahk2Exe-AddResource WAVE sounds\num9pad.wav
;@Ahk2Exe-AddResource WAVE sounds\numApad.wav
;@Ahk2Exe-AddResource WAVE sounds\numpads.wav
;@Ahk2Exe-AddResource WAVE sounds\otherDistinctKeys.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysArrowsD.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysArrowsL.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysArrowsR.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysArrowsU.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysBksp.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysDel.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysEnd.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysEnter.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysHome.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysPgDn.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysPgUp.wav
;@Ahk2Exe-AddResource WAVE sounds\typingkeysSpace.wav
;@Ahk2Exe-AddResource LIB Lib\keypress-mouse-functions.ahk
;@Ahk2Exe-AddResource LIB Lib\keypress-mouse-ripples-functions.ahk
;@Ahk2Exe-AddResource LIB Lib\keypress-beeperz-functions.ahk
;@Ahk2Exe-AddResource LIB Lib\keypress-keystrokes-helper.ahk
;@Ahk2Exe-AddResource LIB Lib\keypress-numpadmouse.ahk
;@Ahk2Exe-AddResource LIB Lib\keypress-typing-aid.ahk
;@Ahk2Exe-AddResource Lib\paypal.bmp, 100
;@Ahk2Exe-SetMainIcon Lib\keypress.ico
;@Ahk2Exe-SetName KeyPress OSD v4
;@Ahk2Exe-SetDescription KeyPress OSD v4 [mirror keyboard and mouse usage]
;@Ahk2Exe-SetVersion 4.36.7.1
;@Ahk2Exe-SetCopyright Marius Şucan (2017-2018)
;@Ahk2Exe-SetCompanyName keypressosd.com
;@Ahk2Exe-SetOrigFilename keypress-osd.ahk
;================================================================
; Section 0. Auto-exec.
;================================================================
; Script Initialization
#SingleInstance Force
#NoEnv
#MaxMem 128
#ClipboardTimeout 3000
#MaxHotkeysPerInterval 500
#MaxThreads 255
#MaxThreadsPerHotkey 255
#MaxThreadsBuffer On
DetectHiddenWindows, On
; #Warn Debug
ComObjError(false)
SetTitleMatchMode, 2
SetBatchLines, -1
ListLines, Off
SetWorkingDir, %A_ScriptDir%
Critical, On
ToolTip, Initializing...
Menu, Tray, UseErrorLevel
Menu, Tray, NoStandard
Menu, Tray, Add, E&xit, KillScript
Menu, Tray, Add,
Menu, Tray, Add, Initializing..., dummy
Menu, Tray, Disable, Initializing...
Menu, Tray, Tip, KeyPress OSD: Initializing...
If !A_IsCompiled
Menu, Tray, Icon, Lib\keypress.ico
; Default Settings
Global IniFile := "keypress-osd.ini"
, LangFile := "keypress-osd-languages.ini"
, WordPairsFile := "keypress-osd-pairs.ini"
, DoNotBindDeadKeys := 0
, DoNotBindAltGrDeadKeys := 0
, AutoDetectKBD := 1 ; at start, detect keyboard layout
, ConstantAutoDetect := 1 ; continuously check if the keyboard layout changed; if AutoDetectKBD=0, this is ignored
, SilentDetection := 0 ; do not display information about language switching
, AudioAlerts := 0 ; generate beeps when key bindings fail
, EnforceSluggishSynch := 0
, EnableAltGr := 1
, AltHook2keysUser := 1
, TypingDelaysScaleUser := 7
, UseMUInames := 1
, NoRestartLangChange := 1
, EnableClipManager := 0
, ClippyIgnoreHideOSD := 0
, MaximumTextClips := 10
, MaxRTFtextClipLen := 60000
, DoNotPasteClippy := 0
, DisableTypingMode := 0
, OnlyTypingMode := 0
, AlternateTypingMode := 1
, EnableTypingHistory := 0
, ExpandWords := 0
, NoExpandAfterTuser := 4 ; in seconds
, EnterErasesLine := 1
, PgUDasHE := 0 ; page up/down behaves like home/end
, UpDownAsHE := 0 ; up/down behaves like home/End
, UpDownAsLR := 0 ; up/down behaves like Left/Right
, ShowDeadKeys := 0
, ShowSingleKey := 1 ; show only key combinations ; it disables typing mode
, HideAnnoyingKeys := 1 ; Left click and PrintScreen can easily get in the way.
, ShowMouseButton := 1 ; in the OSD
, ShowSingleModifierKey := 1 ; make it display Ctrl, Alt, Shift when pressed alone
, DifferModifiers := 0 ; differentiate between left and right modifiers
, ShowPrevKey := 1 ; show previously pressed key, if pressed quickly in succession
, ShowPrevKeyDelay := 300
, ShowKeyCount := 1 ; count how many times a key is pressed
, ShowKeyCountFired := 0 ; show only key presses (0) or catch key fires as well (1)
, NeverDisplayOSD := 0
, MouseOSDbehavior := 1
, ReturnToTypingUser := 20 ; in seconds
, DisplayTimeTypingUser := 10 ; in seconds
, AlternativeJumps := 0
, SendJumpKeys := 0
, MediateNavKeys := 0
, OSDsynchShortcuts := 1
, EraseTextWinChange := 0
, PasteOnClick := 1
, DisplayTimeUser := 3 ; in seconds
, DragOSDmode := 0
, JumpHover := 0
, OSDborder := 0
, GUIposition := 1 ; toggle between positions with Ctrl + Alt + Shift + F9
, GuiXa := 40
, GuiYa := 250
, GuiXb := 700
, GuiYb := 500
, GuiWidth := 350
, MaxGuiWidth := 550
, FontName := (A_OSVersion="WIN_XP" && FileExist(A_WinDir "\Fonts\ARIALUNI.TF")) ? "Arial Unicode MS" : "Arial"
, FontSize := 20
, MinFontSize := 15
, AutoScaleFont := 0
, PrefsLargeFonts := 0
, OSDalignment1 := 3 ; 1 = left ; 2 = center ; 3 = right
, OSDalignment2 := 1 ; 1 = left ; 2 = center ; 3 = right
, OSDbgrColor := "131209"
, OSDtextColor := "FFFEFA"
, CapsColorHighlight := "88AAff"
, TypingColorHighlight := "12E217"
, OSDshowLEDs := 1
, OSDautosize := 1 ; make adjustments to the growth factors to match your font size
, OSDsizingFactorW := 0
, OSDsizingFactor := calcOSDresizeFactor("A",1)
, OSDsizingFactorH := 86
, OutputOSDtoToolTip := 0
, ShowLangCode := 0
; Sound-related settings
, CapslockBeeper := 1 ; only when the key is released
, ToggleKeysBeeper := 1
, KeyBeeper := 0 ; only when the key is released
, DeadKeyBeeper := 1
, ModBeeper := 0 ; beeps for every modifier, when released
, MouseBeeper := 0 ; if both, ShowMouseButton and ShowMouseVclick are disabled, mouse click beeps will never occur
, TypingBeepers := 0
, DTMFbeepers := 0
, BeepFiringKeys := 0
, BeepSentry := 0
, BeepsVolume := 60
, SilentMode := 0
, PrioritizeBeepers := 0 ; this will probably make the OSD stall
, ClipMonitor := 1 ; show clipboard changes
, ShiftDisableCaps := 1
; Cursor and caret settings
, ShowMouseHalo := 0 ; constantly highlight mouse cursor
, ShowMouseIdle := 0 ; locate an idling mouse with a flashing box
, ShowMouseVclick := 0 ; shows visual indicators for different mouse clicks
, ShowMouseRipples := 0
, ShowCaretHalo := 0
, MouseHaloAlpha := 90 ; from 0 to 255
, MouseHaloColor := "EEDD00" ; HEX format also accepted
, MouseHaloRadius := 75
, MouseIdleAfter := 10 ; in seconds
, MouseIdleAlpha := 70 ; from 0 to 255
, MouseIdleColor := "333333"
, MouseIdleRadius := 130
, MouseIdleFlash := 1
, HideMhalosMcurHidden := 1
, MouseVclickAlpha := 150 ; from 0 to 255
, MouseVclickColor := "555599"
, MouseVclickScaleUser := 10
, MouseRippleMaxSize := 140
, MouseRippleThickness := 10
, MouseRippleFrequency := 15
, MouseRippleLbtnColor := "ff2211"
, MouseRippleMbtnColor := "33cc33"
, MouseRippleRbtnColor := "4499ff"
, MouseRippleWbtnColor := "888888"
, MouseRippleOpacity := 160
, CaretHaloAlpha := 128 ; from 0 to 255
, CaretHaloColor := "BBAA99" ; HEX format also accepted
, CaretHaloWidth := 25
, CaretHaloHeight := 30
, CaretHaloShape := 2
, CaretHaloThick := 0
, CaretHaloFlash := 1
; Mouse keys
, MouseKeys := 0
, MouseNumpadSpeed1 := 1
, MouseNumpadAccel1 := 5
, MouseNumpadTopSpeed1 := 35
, MouseWheelSpeed := 7
, MouseCapsSpeed := 2
, MouseKeysWrap := 0
, MouseKeysHalo := 1
, MouseKeysHaloColor := "22EE11"
, MouseKeysHaloRadius := 45
; Script's own global shortcuts (hotkeys)
, GlobalKBDhotkeys := 1 ; Enable system-wide shortcuts (hotkeys)
, GlobalKBDsNoIntercept := 0 ; Allow host apps to receive the same hotkeys
, KBDaltTypeMode := "#+Insert"
, KBDshowEntireText := "(Disabled)"
, KBDnewTXTexpand := "^\"
, KBDpasteOSDcnt1 := "^!Insert"
, KBDpasteOSDcnt2 := "^#Insert"
, KBDsynchApp1 := "#Insert"
, KBDsynchApp2 := "#!Insert"
, KBDsuspend := "+Pause"
, KBDTglNeverOSD := "!+^F8"
, KBDTglPosition := "!+^F9"
, KBDTglSilence := "!+^F10"
, KBDidLangNow := "!+^F11"
, KBDReload := "!+^F12"
, KBDclippyMenu := "#v"
, DoBackup := 0 ; if enabled, each update will backup previous files to a separate folder
, ShowPreview := 0 ; Show OSD preview at Settings
, ThisFile := A_ScriptName
, SafeModeExec := 0
, DownloadExternalFiles := 1
; Release info
, Version := "4.36.7.1"
, ReleaseDate := "2018 / 08 / 15"
; Unicode symbols and characters
, CSthin := "░" ; light gray
, CSmid := "▒" ; gray
, CSdrk := "▓" ; dark gray
, CSblk := "█" ; full block
, CSpwd := "🞘" ; mask private text
; Possible caret symbols; all are WStr chars
, Lola := "│" ; Main caret │
, Lola2 := "┇" ; Caret [selection mode] ║
, CSmo := "║" ; When a modifier is pressed
; symbols that appear when the caret position
; does not change on different key presses
, CSle := "┤" ; Left
, CSri := "├" ; Right
, CSup := "┴" ; Up
, CSdo := "┬" ; Down
, CSho := "╡" ; Home
, CSen := "╞" ; End
, CSpu := "╨" ; Page Up
, Cspd := "╥" ; Page Down
, CSba := "╣" ; Backspace
, CSde := "╠" ; Delete
; dead keys related
, CSx1 := "▫" ; place-holder
, CSx2 := "▫│"
, CSx3 := "▪" ; place-holder
, CSx4 := "◐"
, REx1 := "i)(▫│)" ; RegEx with WStr
, hMutex, KPhasCrashed, ScriptInitialized, RegisteredUser, SerialCode
, TrialPeriodLeft := 10, GratuicielMode := 1, FirstRun := 1, appName := "KeyPress OSD"
, KPregEntry := "HKEY_CURRENT_USER\SOFTWARE\KeyPressOSD\v4"
; Check if INIT previously failed or if KP is running and then load settings.
; These functions are in Section 8.
RegRead, InitCheckReg, %KPregEntry%, Initializing
If (InitCheckReg="Yes")
RegWrite, REG_SZ, %KPregEntry%, Initializing, No
Else
RegWrite, REG_SZ, %KPregEntry%, Initializing, Yes
CheckIfRunning()
If A_IsCompiled ; If you don't condition this you'll get bogus 'app running' for each running instance of Autohotkey.exe regardless of it running this script or any other, or even being AHK_H or AHK_L
{
If DllCall("kernel32\OpenMutexW", "UInt", 0x100000, "UInt", False, "Str", ThisFile)
CheckIfRunning(1)
hMutex := DllCall("kernel32\CreateMutexW", "Ptr", NULL, "UInt", False, "Str", ThisFile)
Sleep, 5
}
StringReplace, ahkVer, A_AhkVersion,.,, All
StringLeft, ahkVer, ahkVer, 4
If (ahkVer<1127)
TrayTip, %appName%: WARNING, It seems you are running an old version of AHK: %A_AhkVersion%. The script may malfunction.
If (!A_IsUnicode)
{
SoundBeep
TrayTip, %appName%: WARNING, It seems you are not running the Unicode edition of AHK: The script will malfunction.
}
INIaction(0, "FirstRun", "SavedSettings")
If (FirstRun=0)
{
INIsettings(0)
} Else
{
If (FirstRun!=2)
RegWrite, REG_SZ, %KPregEntry%, FirstRunTime, %A_Now%
CheckSettings()
INIsettings(1)
}
If (InitCheckReg="Yes")
{
SafeModeExec := KPhasCrashed := 1
AutoDetectKBD := ConstantAutoDetect := ClipMonitor := EnableClipManager := 0
TrayTip, %appName%: Safe mode, Started in Safe mode due to a crash, 5
}
; Initialization variables. Altering these may lead to undesired results.
Global Debug := 0 ; for testing purposes
, MouseVclickScale := MouseVclickScaleUser/10
, DisplayTime := DisplayTimeUser*1000
, DisplayTimeTyping := DisplayTimeTypingUser*1000
, ReturnToTypingDelay := ReturnToTypingUser*1000
, OSDalignment := (GUIposition=1) ? OSDalignment2 : OSDalignment1
, GuiX := GuiX ? GuiX : GuiXa
, GuiY := GuiY ? GuiY : GuiYa
, GuiHeight := 50 ; a default, later overriden
, smallLEDheight := "8"
, MaxAllowedGuiWidth := (OSDautosize=1) ? MaxGuiWidth : GuiWidth
, OSDvisible := 0
, OSDcontentOutput := ""
, Prefixed := 0 ; hack used to determine if last keypress had a modifier
, KeyCount := 0
, lastClickTimer := 0
, MainFontSize := FontSize
, Tickcount_start2 := A_TickCount ; timer to keep track of OSD redraws
, Tickcount_start := 0 ; timer to count repeated key presses
, Typed := "" ; hack used to determine if user is writing
, BackTypeCtrl := ""
, BackTypdUndo := ""
, ClippyFolder := "ClipsSaved"
, TypedKeysHistory := ""
, LastTypedSince := 0
, LastTypedKey := ""
, EditingField := "3"
, EditField0 := ""
, EditField1 := " "
, EditField2 := " "
, EditField3 := " "
, EditField4 := ""
, VisibleTextField := ""
, MaxTextChars := "4" ; max. chars visible in the OSD in typing mode; default value, later overriden
, Text_width := 60 ; default value, later overriden using GetTextExtentPoint()
, CaretPos := "1"
, PressKeyRecorded := 1
, ExpandWordsList := []
, ExpandWordsListEdit := ""
, NoExpandAfter := NoExpandAfterTuser*1000
, LastMatchedExpandPair := ""
, ExternalKeyStrokeRecvd := "" ; for alternative hooks
, SecondaryTypingMode := 0
, OnMSGchar := ""
, OnMSGdeadChar := ""
, AlternativeHook2keys := (AltHook2keysUser=0) ? 0 : 1
, TypingDelaysScale := TypingDelaysScaleUser / 10
, CurrentKBD := "Default: English US"
, LoadedLangz := 0
, KbLayoutRaw := 0
, IsLangRTL := 0
, DKnamez := CSx3
, DeadKeys := 0
, DeadKeyPressed := "9950"
, TrueRmDkSymbol := ""
, DKnotShifted_list := ""
, DKshift_list := ""
, DKaltGR_list := ""
, AllDKsList := ""
, LangIndicWidth := 0
, MousePosition := ""
, Modifiers_temp := 0
, DoNotRepeatTimer := 0
, nbrLines := 1
, LastGlobalKeyInvoked := 0
, LastMultiLineInvoked := 0
, Window2Activate := " "
, Window2ActivateHwnd := ""
, FontList := []
, CurrentPrefWindow := ""
, PrefOpen := 0
, MissingAudios := 0
, GlobalPrefix := ""
, LargeUIfontValue := 13
, CurrentDPI := A_ScreenDPI
, InstKBDsWinOpen, CurrentTab, AnyWindowOpen := 0
, PreviewWindowText := "Text preview " Lola "window... " Lola2
, MainModsList := ["LCtrl", "RCtrl", "LAlt", "RAlt", "LShift", "RShift", "LWin", "RWin"]
, regedKBDhotkeys := [] ; dynamic list of global keyboard shortcuts registered
, GlobalKBDsList := "KBDaltTypeMode,KBDnewTXTexpand,KBDpasteOSDcnt1,KBDpasteOSDcnt2,KBDsynchApp1,KBDsynchApp2
,KBDTglNeverOSD,KBDTglPosition,KBDTglSilence,KBDidLangNow,KBDReload,KBDsuspend,KBDclippyMenu,KBDshowEntireText"
, 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 ]]"
, hKPOtyping, hOSD, OSDhandles, dragOSDhandles, ColorPickerHandles, hMain := A_ScriptHwnd
, CCLVO := "-E0x200 +Border -Hdr -Multi +ReadOnly Report AltSubmit gsetColors"
, Emojis := "x)(☀|🤣|👌|☹|☺|♥|⛄|❤|️|🌙|🌛|🌜|🌷|🌸|🎄|👄|👋|👍|👏|👙|👳|👶|👼|👽|💁|💃|💋|🙄
|💏|💓|💕|💖|💗|💞|💤|💯|😀|😁|😂|😃|😄|😆|😇|😈|😉|😊|😋|😌|😍|😎|😐|😓|😔|😕|😗|🤗
|😘|😙|😚|😛|😜|😝|😞|😡|😢|😥|😩|😫|😭|😮|😲|😳|😴|😶|🙁|🙂|🙃|🙈|🙊|🙏|🤔|😏|🤢)"
, MouseFuncThread, MouseNumpadThread, MouseRipplesThread, SoundsThread, KeyStrokesThread, TypingAidThread
, IsMouseFile, IsMouseNumpadFile, IsRipplesFile, IsSoundsFile, IsKeystrokesFile, IsTypingAidFile, NoAhkH
, ClipDataMD5s, CurrentClippyCount := 0
, hWinMM := DllCall("kernel32\LoadLibraryW", "Str", "winmm.dll", "Ptr")
, volL, VolR := GetVolume(VolL)
, ScriptelSuspendel := 0
, ForceUpdate := 0 ; this will be used when major changes require full update
, BaseURL := "http://marius.sucan.ro/media/files/blog/ahk-scripts/"
; Initializations of the core components and functionality
CreateOSDGUI()
VerifyNonCrucialFiles()
Sleep, 5
If (SafeModeExec!=1)
{
GoSub, CheckThis
InitAHKhThreads()
SetMyVolume()
}
Sleep, 5
IdentifyKBDlayoutWrapper()
Sleep, 5
CreateHotkey()
CreateGlobalShortcuts()
If (ClipMonitor=1 || EnableClipManager=1)
OnClipboardChange("ClipChanged")
If (ExpandWords=1 && DisableTypingMode=0)
InitExpandableWords()
If (EnableClipManager=1 && TrialPeriodLeft>0)
InitClipboardManager()
hCursM := DllCall("user32\LoadCursorW", "Ptr", NULL, "Int", 32646, "Ptr") ; IDC_SIZEALL
hCursH := DllCall("user32\LoadCursorW", "Ptr", NULL, "Int", 32649, "Ptr") ; IDC_HAND
OnMessage(0x200, "MouseMove") ; WM_MOUSEMOVE
If DllCall("wtsapi32\WTSRegisterSessionNotification", "Ptr", hMain, "UInt", 0)
OnMessage(0x02B1, "WM_WTSSESSION_CHANGE")
InitializeTray()
ModsLEDsIndicatorsManager()
RegWrite, REG_SZ, %KPregEntry%, Initializing, No
ScriptInitialized := 1 ; the end of the autoexec section and INIT
ToolTip
Return
;================================================================
; Section 1. Functions called by Hotkey command bindings created
; by CreateHotkey() from Section 4.
; - The functions here call typing mode related functions from Section 2.
; In particular TypedLetter().
; - If typing mode is disabled, almost every function from here calls
; GetKeyStr() to get its name and then display it in the OSD with
; ShowHotkey().
; - The two mentioned functions are in Section 3.
;================================================================
OnMudPressed() {
SetTimer, modsTimer, 100, 50
If (NeverDisplayOSD=1 && OutputOSDtoToolTip=0)
Return
Static repeatCount := 1
, modPressedTimer := 1
, prevPrefix
BackTypeCtrl := Typed
fl_prefix := checkIfModsHeld(0)
StringReplace, keya, A_ThisHotkey, ~*,
fl_prefix .= keya "+"
fl_prefix := CompactModifiers(fl_prefix)
; ToolTip, %A_THISHOTKEY% -- %fl_prefix%
Sort, fl_prefix, U D+
fl_prefix := RTrim(fl_prefix, "+")
StringReplace, fl_prefix, fl_prefix, +, %A_Space%+%A_Space%, All
If (A_TickCount-Tickcount_start2 < 60) && (fl_prefix=prevPrefix)
Return
prevPrefix := fl_prefix
CapsLockState := GetKeyState("CapsLock", "T")
If (InStr(fl_prefix, "Shift") && ShiftDisableCaps=1
&& CapsLockState=1 && (A_TickCount-Tickcount_start2 > 100))
{
SetCapsLockState, off
If (MouseKeys=1) && (A_TickCount-Tickcount_start2 > 50)
MouseNumpadThread.ahkPostFunction["ToggleCapsLock", 1]
If (OSDshowLEDs=1)
GuiControl, OSD:, CapsLED, 0
}
If (StrLen(Typed)>1 && (A_TickCount-LastTypedSince < 4000)
&& (A_TickCount-modPressedTimer > 70) && OSDvisible=1)
caretSymbolChangeIndicator(CSmo)
If (A_TickCount-modPressedTimer > 150) && (OSDshowLEDs=1)
GuiControl, OSD:, ModsLED, 100
modPressedTimer := A_TickCount
SetTimer, ModsLEDsIndicatorsManager, -370, 50
If (ShowSingleModifierKey=0) || (A_TickCount-Tickcount_start2<45)
Return
If (InStr(fl_prefix, Modifiers_temp) && !Typed && ShowKeyCount=1
&& (A_TickCount - lastClickTimer > ShowPrevKeyDelay*3))
{
valid_count := 1
If (repeatCount>1)
KeyCount := 0.1
} Else
{
valid_count := 0
Modifiers_temp := fl_prefix
If !Prefixed
KeyCount := 0.1
}
If (valid_count=1 && ShowKeyCountFired=0 && ShowKeyCount=1 && !InStr(fl_prefix, "AltGr"))
{
trackingPresses := (Tickcount_start2 - Tickcount_start < 50) ? 1 : 0
repeatCount := (trackingPresses=0 && repeatCount<1) ? repeatCount+1 : repeatCount
If (trackingPresses=1)
repeatCount := !repeatCount ? 1 : repeatCount+1
ShowKeyCountValid := 1
} Else If (valid_count=1 && ShowKeyCountFired=1 && ShowKeyCount=1)
{
repeatCount := !repeatCount ? 0 : repeatCount+1
If InStr(fl_prefix, "AltGr") && repeatCount>3
repeatCount := repeatCount-1+0.49
ShowKeyCountValid := 1
} Else
{
repeatCount := 1
ShowKeyCountValid := 0
}
If (ShowKeyCountValid=1)
{
If !InStr(fl_prefix, "+")
{
Modifiers_temp := fl_prefix
If Round(repeatCount)>1
fl_prefix .= " (" Round(repeatCount) ")"
} Else (repeatCount := 1)
}
If (StrLen(Typed)>1 && OSDvisible=1 && (A_TickCount-LastTypedSince < 4000))
|| (ShowSingleKey = 0) || (OnlyTypingMode=1)
|| ((A_TickCount-Tickcount_start > 1800) && OSDvisible=1 && !Typed && KeyCount>7)
|| (A_TickCount - lastClickTimer < ShowPrevKeyDelay*3)
{
Sleep, 1
} Else
{
If (A_TickCount-Tickcount_start2>50)
ShowHotkey(fl_prefix)
SetTimer, HideGUI, % -DisplayTime
SetTimer, ReturnToTyped, % -DisplayTime/4
}
}
OnMouseKeysPressed(key) {
Thread, Priority, -20
Critical, on
Static oldKey, miniCounter, lastInvoked := 1
If (A_TickCount-lastInvoked < 200) && !InStr(key, "Double click")
Return
lastInvoked := A_TickCount
Global lastClickTimer := A_TickCount
If (ShowMouseButton=1 && OnlyTypingMode=0 && PrefOpen=0)
&& (NeverDisplayOSD=0 || OutputOSDtoToolTip=1)
{
If !InStr(key, "lock")
SetTimer, ClicksTimer, 400, 50
If !(InStr(key, "left click") && StrLen(key)<12 && HideAnnoyingKeys=1)
{
Sleep, 150
miniCounter := (ShowKeyCount=0 || key!=oldKey || KeyCount>=1) ? 1 : miniCounter + 1
oldKey := key
keyCounter := (miniCounter>1 && ShowKeyCount=1) ? " (" miniCounter ")" : ""
KeyCount := 0.3
ShowHotkey(key keyCounter)
}
SetTimer, HideGUI, % -DisplayTime
If (StrLen(Typed)>2 && miniCounter<10)
SetTimer, ReturnToTyped, % -DisplayTime/4
}
If (ShowMouseRipples=1 && IsRipplesFile)
MouseRipplesThread.ahkPostFunction("MouseKeysEvent", key)
If (MouseBeeper=1 && IsSoundsFile)
SoundsThread.ahkPostFunction("OnMousePressed", key)
If (ShowMouseVclick=1 && IsMouseFile)
{
If InStr(key, "left click")
MouseFuncThread.ahkPostFunction("ShowMouseClick", "LButton")
If InStr(key, "right click")
MouseFuncThread.ahkPostFunction("ShowMouseClick", "RButton")
If InStr(key, "middle click")
MouseFuncThread.ahkPostFunction("ShowMouseClick", "MButton")
If InStr(key, "wheel up")
MouseFuncThread.ahkPostFunction("ShowMouseClick", "WheelUp")
If InStr(key, "wheel down")
MouseFuncThread.ahkPostFunction("ShowMouseClick", "WheelDown")
}
LastMatchedExpandPair := ""
}
OnMousePressed() {
Thread, Priority, -20
Critical, off
SetTimer, ClicksTimer, 400, 50
If (OnlyTypingMode=1) || (OutputOSDtoToolTip=0 && NeverDisplayOSD=1)
Return
Global lastClickTimer := A_TickCount
Try {
key := GetKeyStr()
If (ShowMouseButton=1)
{
If (EnableTypingHistory=1)
EditField4 := StrLen(Typed)>5 ? Typed : EditField4
Typed := (OnlyTypingMode=1) ? Typed : "" ; concerning TypedLetter(" ") - it resets the content of the OSD
ShowHotkey(key)
SetTimer, HideGUI, % -DisplayTime
}
}
LastMatchedExpandPair := ""
}
OnRLeftPressed() {
LastMatchedExpandPair := ""
Try {
key := GetKeyStr()
If (A_TickCount-LastTypedSince < ReturnToTypingDelay)
&& StrLen(Typed)>1 && (DisableTypingMode=0)
&& (key ~= "i)^((.?Shift \+ )?(Left|Right))")
&& (ShowSingleKey=1) && (KeyCount<10)
{
deadKeyProcessing()
If (key ~= "i)^(Left)")
CaretMover(0)
If (key ~= "i)^(Right)")
CaretMover(2)
If (key ~= "i)^(.?Shift \+ Left)")
CaretMoverSel(-1)
If (key ~= "i)^(.?Shift \+ Right)")
CaretMoverSel(1)
ShowHotkey(VisibleTextField)
SetTimer, HideGUI, % -DisplayTimeTyping
If (CaretPos!=StrLen(Typed) && CaretPos!=1)
{
Global LastTypedSince := A_TickCount
KeyCount := 1
} Else If (KeyCount>1 || OnlyTypingMode=1)
{
If InStr(key, "left")
CaretSymbolChangeIndicator(CSle, 300)
If InStr(key, "right")
CaretSymbolChangeIndicator(CSri, 300)
}
}
If (Prefixed && !(key ~= "i)^(.?Shift \+)")) || StrLen(Typed)<2
|| (A_TickCount-LastTypedSince > (ReturnToTypingDelay+50))
|| (KeyCount>10 && OnlyTypingMode=0)
{
If (KeyCount>10 && OnlyTypingMode=0)
Global LastTypedSince := A_TickCount - ReturnToTypingDelay
If (EnableTypingHistory=1 && Prefixed && OnlyTypingMode=0)
EditField4 := StrLen(Typed)>5 ? Typed : EditField4
If (StrLen(Typed)<2)
Typed := (OnlyTypingMode=1) ? Typed : ""
If (OnlyTypingMode!=1)
{
ShowHotkey(key)
SetTimer, HideGUI, % -DisplayTime
}
}
If (DisableTypingMode=1) || (Prefixed && !(key ~= "i)^(.?Shift \+)"))
Typed := (OnlyTypingMode=1) ? Typed : ""
}
If (EnforceSluggishSynch=1 && SecondaryTypingMode=0)
{
If (A_ThisHotkey="$Left")
SendInput, {Left}
If (A_ThisHotkey="$Right")
SendInput, {Right}
If (A_ThisHotkey="$+Left")
SendInput, +{Left}
If (A_ThisHotkey="$+Right")
SendInput, +{Right}
}
}
OnUpDownPressed() {
LastMatchedExpandPair := ""
Try {
key := GetKeyStr()
If (A_TickCount-LastTypedSince < ReturnToTypingDelay)
&& StrLen(Typed)>1 && (DisableTypingMode=0)
&& (key ~= "i)^((.?Shift \+ )?(Up|Down))")
&& (ShowSingleKey=1) && (KeyCount<10)
{
deadKeyProcessing()
If (CaretPos!=StrLen(Typed) && CaretPos!=1)
KeyCount := (UpDownAsHE=0 && UpDownAsLR=0) ? KeyCount : 1
If (UpDownAsHE=0 && UpDownAsLR=0 && !InStr(key, "shift"))
{
StringReplace, Typed, Typed, %Lola2%
CalcVisibleText()
}
If (UpDownAsHE=1 && UpDownAsLR=0)
{
StringGetPos, CaretPos3, Typed, %Lola%
StringGetPos, CaretPos4, Typed, %Lola2%
If (key ~= "i)^(Up)") && (CaretPos3!=0 || CaretPos4!=-1)
{
StringReplace, Typed, Typed, %Lola%
StringReplace, Typed, Typed, %Lola2%
CaretPos := 1
Typed := ST_Insert(Lola, Typed, CaretPos)
MaxTextChars := MaxTextChars*2
}
If (key ~= "i)^(Down)")
{
StringReplace, Typed, Typed, %Lola%
StringReplace, Typed, Typed, %Lola2%
CaretPos := StrLen(Typed)+1
Typed := ST_Insert(Lola, Typed, CaretPos)
MaxTextChars := StrLen(Typed)+2
}
If (key ~= "i)^(.?Shift \+ Down)")
SelectHomeEnd(1)
If (key ~= "i)^(.?Shift \+ Up)")
SelectHomeEnd(0)
CalcVisibleText()
}
If (UpDownAsLR=1 && UpDownAsHE=0)
{
If (key ~= "i)^(Up)")
CaretMover(0)
If (key ~= "i)^(Down)")
CaretMover(2)
If (key ~= "i)^(.?Shift \+ Up)")
CaretMoverSel(-1)
If (key ~= "i)^(.?Shift \+ Down)")
CaretMoverSel(1)
}
Global LastTypedSince := A_TickCount
ShowHotkey(VisibleTextField)
If (CaretPos=StrLen(Typed) || CaretPos=1
|| (UpDownAsHE=0 && UpDownAsLR=0))
{
If (InStr(key, "up") && (KeyCount>1 || OnlyTypingMode=1))
caretSymbolChangeIndicator(CSup, 300)
If (InStr(key, "down") && (KeyCount>1 || OnlyTypingMode=1))
caretSymbolChangeIndicator(CSdo, 300)
}
SetTimer, HideGUI, % -DisplayTimeTyping
}
If (Prefixed && !(key ~= "i)^(.?Shift \+)") || StrLen(Typed)<1
|| (A_TickCount-LastTypedSince > (ReturnToTypingDelay+50))
|| (KeyCount>10 && OnlyTypingMode=0))
{
If (KeyCount>10 && OnlyTypingMode=0)
Global LastTypedSince := A_TickCount - ReturnToTypingDelay
If (OnlyTypingMode!=1)
{
ShowHotkey(key)
SetTimer, HideGUI, % -DisplayTime
}
}
If (DisableTypingMode=1) || (Prefixed && !(key ~= "i)^(.?Shift \+)"))
Typed := (OnlyTypingMode=1) ? Typed : ""
}
}
OnHomeEndPressed() {
LastMatchedExpandPair := ""
FilterText(1, exKaretPos, exKaretPosSelly, InitialTxtLength)
Try {
key := GetKeyStr()
If (A_TickCount-LastTypedSince < ReturnToTypingDelay)
&& StrLen(Typed)>0 && (DisableTypingMode=0)
&& (key ~= "i)^((.?Shift \+ )?(Home|End))")
&& (ShowSingleKey=1) && (KeyCount<10)
{
deadKeyProcessing()
If (key ~= "i)^(.?Shift \+ End)") || InStr(A_ThisHotkey, "~+End")
{
SelectHomeEnd(1)
skipRest := 1
}
If (key ~= "i)^(.?Shift \+ Home)") || InStr(A_ThisHotkey, "~+Home")
{
SelectHomeEnd(0)
If (StrLen(Typed)<3)
selectAllText()
skipRest := 1
}
if InStr(Typed, Lola2)
selPresent := 1
VisibleTxtLength := StrLen(VisibleTextField)
TypedLength := StrLen(Typed)
StringGetPos, CaretPos3, Typed, %Lola%
StringGetPos, CaretPos4, Typed, %Lola2%
If ((key ~= "i)^(Home)") && skipRest!=1
&& IsLangRTL=0 && MediateNavKeys=1 && selPresent=1)
{
CaretMover(0)
SendInput, {Left}
skipRest := dropSel := 1
}
If ((key ~= "i)^(End)") && skipRest!=1
&& IsLangRTL=0 && MediateNavKeys=1 && selPresent=1)
{
CaretMover(2)
SendInput, {Right}
skipRest := dropSel := 1
}
If ((key ~= "i)^(Home)") && skipRest!=1 && IsLangRTL=0)
{
If (CaretPos3!=0 || CaretPos4!=-1)
{
StringReplace, Typed, Typed, %Lola%
StringReplace, Typed, Typed, %Lola2%
If (VisibleTxtLength*3<InitialTxtLength) && (MediateNavKeys=1
&& TypedLength=InitialTxtLength && selPresent!=1)
{
CaretPos := exKaretPos - Round(InitialTxtLength*0.25) + 2
MaxTextChars := Round(MaxTextChars*1.05)