-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyToggles.ahk
More file actions
1869 lines (1604 loc) · 77.3 KB
/
Copy pathKeyToggles.ahk
File metadata and controls
1869 lines (1604 loc) · 77.3 KB
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
; KeyToggles v2.4
/*
TODO
add application profiles (https://stackoverflow.com/questions/45190170/how-can-i-make-this-ini-file-into-a-listview-in-autohotkey)
add support for hotkey modifiers (e.g., Ctrl+F1) https://www.autohotkey.com/docs/v2/Hotkeys.htm#Symbols
add update checker (https://www.reddit.com/r/AutoHotkey/comments/1rio81z/github_repo_update_checker_for_ahk_any_anything)
fix "Error: Target window not found: g_iWindowID := WinGetID(l_sWinTitle)" in OnFocusChanged()
fix modifiers still toggled while clicking outside the window
fix toggles not working when physically holding another toggle key (https://www.reddit.com/r/AutoHotkey/comments/oh65o2/comment/h4phdwu)
look into code obfuscation https://www.autohotkey.com/boards/viewtopic.php?f=28&t=42494
redo window detection (https://www.reddit.com/r/AutoHotkey/comments/nmewd1/resize_and_move_a_window_every_time_it_gets/gzoogts)
refactor the project to use classes (https://www.reddit.com/r/AutoHotkey/comments/1sumsfy/comment/ok3us2f)
register/unregister system keys when toggling the option in the menu
replace "ahk_id " g_iWindowID with window name and process name
replace sleeps with timers or SetKeyDelay (SendEvent only)
replace ternary operators with coalescing ?? operators where possible
simpler solution for system keys? https://www.reddit.com/r/AutoHotkey/comments/1t5r12b/comment/okcfvod
https://dev.to/manikandan/how-to-use-ai-models-locally-in-vs-code-with-the-continue-plugin-with-multi-model-switching-3na0
*/
#Requires Autohotkey v2.0 ; Display an error and quit if this version requirement is not met.
#SingleInstance force ; Allow only a single instance of the script to run.
#Warn ; Enable warnings to assist with detecting common errors.
; Constants
KEY_MODE_DISABLED := 0
KEY_MODE_TOGGLE := 1
KEY_MODE_HOLD := 2
KEY_MODE_AUTOFIRE_TOGGLE := 3
KEY_MODE_AUTOFIRE_HOLD := 4
SEND_MODE_EVENT := 0
SEND_MODE_INPUT := 1
SEND_MODE_PLAY := 2
SEND_MODE_INPUTTHENPLAY := 3
class States
{
static bPreviousLogMessagesAdded := false
static bThemePopupShown := false
static bToggleKeysSnapshotTaken := false
}
; Maps
g_mapControls := Map()
g_mapMenus := Map()
g_mapSettings := Map()
g_mapStates := Map(
"bAiming", false,
"bCrouching", false,
"bSprinting", false,
"bAutofireAiming", false,
"bAutofireCrouching", false,
"bAutofireSprinting", false,
"bAutorunning", false,
"bRestoreAiming", false,
"bRestoreAutofireAiming", false,
"bRestoreAutofireCrouching", false,
"bRestoreAutofireSprinting", false,
"bRestoreAutorunning", false,
"bRestoreCrouching", false,
"bRestoreSprinting", false,
)
; Functors
g_fnAutofireAim := 0
g_fnAutofireCrouch := 0
g_fnAutofireSprint := 0
; UI
g_guiBackColor := "White"
g_guiTextColor := "CBlack"
; Others
g_iWindowID := 0
g_sConfigFileName := "KeyToggles.ini"
g_sLogFileName := "KeyToggles.log"
Init()
GetDuplicateHotkeys(p_bFromGUI := true)
{
l_arrHotkeys := [
p_bFromGUI ? g_mapControls["hkAimKey"].Value : g_mapSettings["sAimKey"],
p_bFromGUI ? g_mapControls["hkCrouchKey"].Value : g_mapSettings["sCrouchKey"],
p_bFromGUI ? g_mapControls["hkSprintKey"].Value : g_mapSettings["sSprintKey"],
p_bFromGUI ? g_mapControls["hkAutorunKey"].Value : g_mapSettings["sAutorunKey"],
p_bFromGUI ? g_mapControls["hkForwardKey"].Value : g_mapSettings["sForwardKey"],
p_bFromGUI ? g_mapControls["hkBackwardKey"].Value : g_mapSettings["sBackwardKey"],
p_bFromGUI ? g_mapControls["hkAimAutofireKey"].Value : g_mapSettings["sAimAutofireKey"],
p_bFromGUI ? g_mapControls["hkCrouchAutofireKey"].Value : g_mapSettings["sCrouchAutofireKey"],
p_bFromGUI ? g_mapControls["hkSprintAutofireKey"].Value : g_mapSettings["sSprintAutofireKey"]
]
l_mapHotkeys := Map()
l_sDuplicateHotkeys := ""
for l_sValue in l_arrHotkeys
{
if (l_sValue)
{
; That's a duplicate
if (l_mapHotkeys.Has(l_sValue))
{
if (++l_mapHotkeys[l_sValue] == 2)
l_sDuplicateHotkeys .= l_sDuplicateHotkeys ? ", " l_sValue : l_sValue
}
else
l_mapHotkeys[l_sValue] := 1
}
}
return l_sDuplicateHotkeys
}
GuiAddMenus()
{
g_mapMenus["File"] := l_fileMenu := Menu()
l_fileMenu.Add("Save and exit", GuiMenuHandler)
l_fileMenu.Add("Exit", GuiMenuHandler)
g_mapMenus["View"] := l_viewMenu := Menu()
g_mapMenus["View"].Add("Always on top", GuiMenuHandler)
g_mapMenus["View"].Add("Close to tray", GuiMenuHandler)
g_mapMenus["View"].Add("Dark mode", GuiMenuHandler)
g_mapMenus["View"].Add("Hide window selector from capture", GuiMenuHandler)
g_mapMenus["View"].Add("Minimize to tray", GuiMenuHandler)
g_mapMenus["View"].Add("Remember window positions", GuiMenuHandler)
g_mapMenus["Misc"] := l_miscMenu := Menu()
g_mapMenus["Misc"].Add("Beep on suspend", GuiMenuHandler)
g_mapMenus["Misc"].Add("Enable logging", GuiMenuHandler)
g_mapMenus["Misc"].Add("Fix system keys", GuiMenuHandler)
g_mapMenus["Misc"].Add("Restore autofires on focus", GuiMenuHandler)
g_mapMenus["Misc"].Add("Restore toggles on focus", GuiMenuHandler)
g_mapMenus["Misc"].Add("Run as admin", GuiMenuHandler)
g_mapMenus["Help"] := l_helpMenu := Menu()
l_helpMenu.Add("View log", GuiMenuHandler)
l_helpMenu.Add("Visit website", GuiMenuHandler)
l_helpMenu.Add("About", GuiMenuHandler)
g_guiSettings.MenuBar := l_menuBar := MenuBar()
l_menuBar.Add("&File", l_fileMenu)
l_menuBar.Add("&View", l_viewMenu)
l_menuBar.Add("&Misc", l_miscMenu)
l_menuBar.Add("&Help", l_helpMenu)
GuiMenuUpdate()
}
GuiApplyTheme()
{
; Set theme to dark mode
if (g_mapSettings["bDarkMode"])
{
global g_guiBackColor := "1F1F1F"
global g_guiTextColor := "CWhite"
}
}
; Browse for process executable
GuiButtonBrowse_Click(*)
{
; Turn FileSelect and MsgBox into modals
g_guiSettings.Opt("+OwnDialogs")
; Only allow selecting executables by default
l_sSelectedFile := FileSelect("3", , "Select the target executable file", "Executable Files (*.exe)")
if (l_sSelectedFile)
{
SplitPath(l_sSelectedFile, &l_sFileName)
l_bIsProcessNameValid := IsProcessNameValid(l_sFileName)
; Process name not valid, do nothing
if (l_bIsProcessNameValid != 1)
{
MsgBox('"' l_sFileName '" is not an executable file.', , "Icon!")
return
}
g_mapControls["editProcessName"].Value := l_sFileName
g_mapControls["editWindowName"].Value := ""
}
}
GuiButtonResetDefaults_Click(*)
{
ReadConfigFile("")
GuiMenuUpdate()
GuiUpdate()
SetTimer(OnFocusChanged, 0)
}
; Validate and save settings to the config file
GuiButtonSave_Click(*)
{
if (WriteConfigFile())
{
UnregisterHotkeys()
; Force the hotkeys to be re-registered
global g_iWindowID := 0
ReadConfigFile()
StartFocusCheck()
MsgBox("Settings saved!", , "Iconi Owner" g_guiSettings.Hwnd)
}
}
GuiButtonSelect_Click(*)
{
; Disable the main window to turn the window selector into a modal
g_guiSettings.Opt("+Disabled")
; Create the window selector GUI if it doesn't exist
if !IsSet(g_guiWindowSelector)
{
; Gui
global g_guiWindowSelector := Gui.Call("+Owner" g_guiSettings.Hwnd " -MinimizeBox -MaximizeBox", "Window selector")
g_guiWindowSelector.BackColor := g_guiBackColor
g_guiWindowSelector.SetFont("s10")
g_guiWindowSelector.OnEvent("Close", (*) => g_guiSettings.Opt("-Disabled"))
; Button
g_guiWindowSelector.AddButton("Background" g_guiBackColor " Default w100", "&Refresh").OnEvent("Click", (*) => GuiLV_ReloadProcesses())
; Checkbox
g_guiWindowSelector.SetFont(g_guiTextColor)
g_mapControls["cbExcludeProcesses"] := g_guiWindowSelector.AddCheckbox("Checked", "Exclude common processes")
g_mapControls["cbExcludeProcesses"].OnEvent("Click", (*) => GuiLV_ReloadProcesses())
; ListView
l_iLvWidth := A_ScreenWidth * .41
g_mapControls["lvWindowPicker"] := g_guiWindowSelector.AddListView("Background" g_guiBackColor " -Multi ReadOnly Sort Tile w" l_iLvWidth)
g_mapControls["lvWindowPicker"].OnEvent("DoubleClick", GuiLV_DoubleClick)
; Set the ListView's tooltip to be always on top (https://www.autohotkey.com/boards/viewtopic.php?t=28792)
DetectHiddenWindows(true)
l_iLVTooltipHwnd := DllCall("SendMessage", "ptr", g_mapControls["lvWindowPicker"].Hwnd, "uint", LVM_GETTOOLTIPS := 0x104E, "ptr", 0, "ptr", 0, "ptr")
WinSetAlwaysOnTop(1, "ahk_id " l_iLVTooltipHwnd)
DetectHiddenWindows(false)
}
; Set whether to hide the window selector from capture
DllCall("user32\SetWindowDisplayAffinity", "Int", g_guiWindowSelector.Hwnd, "Int", WDA_EXCLUDEFROMCAPTURE := 0x00000011 * g_mapSettings["bHideFromCapture"])
GuiLV_ReloadProcesses()
g_guiWindowSelector.Show(g_mapSettings["bRememberWindowPositions"] ? "x" g_mapSettings["iSelectorWindowX"] " y" g_mapSettings["iSelectorWindowY"] : "")
}
GuiCB_Click(p_guiCtrl, *)
{
switch p_guiCtrl
{
case g_mapControls["cbAutorun"]:
g_mapSettings["bAutorunMode"] := !g_mapSettings["bAutorunMode"]
g_mapControls["hkAutorunKey"].Enabled := g_mapControls["ddlAutorunKey"].Enabled := g_mapSettings["bAutorunMode"]
g_mapControls["hkBackwardKey"].Enabled := g_mapControls["ddlBackwardKey"].Enabled := g_mapSettings["bAutorunMode"]
g_mapControls["hkForwardKey"].Enabled := g_mapControls["ddlForwardKey"].Enabled := g_mapSettings["bAutorunMode"]
default:
return
}
; We save the changes immediately to avoid having to hit Save
try
{
IniWrite(g_mapSettings["bAutorunMode"], g_sConfigFileName, "General", "autorunMode")
}
catch as e
MsgBox(Format("{1}: {2}.`n`nFile:`t{3}`nLine:`t{4}`nWhat:`t{5}`nStack:`n{6}", type(e), e.Message, e.File, e.Line, e.What, e.Stack), , "Icon! Owner" g_guiSettings.Hwnd)
}
GuiCreate()
{
; Safety check
if IsSet(g_guiSettings)
return
; Arrays
l_arrExtraKeys := ["None", "LButton", "RButton", "MButton", "XButton1", "XButton2", "Space", "Tab", "Enter", "Backspace"]
l_arrKeyModes := ["Disabled", "Toggle", "Hold", "Autofire toggle", "Autofire hold"]
l_arrNotificationTypes := ["Disabled", "System notifications", "Tooltips"]
l_arrSendModes := ["Event", "Input", "Play", "InputThenPlay"]
; Layout constants
l_iCurrentRow := 0
l_iSpacingX := 10
l_iSpacingY := 25
l_iTopY := 5
; Leftmost controls
l_iLeftWidth := 170
l_iLeftX := 25
; Middle controls
l_iMiddleX := l_iLeftX + l_iLeftWidth + l_iSpacingX
l_iMiddleWidth := 170
; Rightmost controls
l_iRightX := l_iMiddleX + l_iMiddleWidth + l_iSpacingX
l_iRightWidth := 100
global g_guiSettings := Gui.Call("+OwnDialogs", "Settings", )
g_guiSettings.BackColor := g_guiBackColor
g_guiSettings.MarginX := 20
g_guiSettings.MarginY := 10
g_guiSettings.SetFont("s10 " g_guiTextColor)
g_guiSettings.OnEvent("Close", (*) => g_mapSettings["bCloseToTray"] ? g_guiSettings.Hide() : ExitApp(1))
g_guiSettings.OnEvent("Size", GuiOnSize)
; General
g_guiSettings.AddGroupBox("x" l_iLeftX - 5 " y" l_iTopY " h" 8*28 + 7 " w" (l_iLeftWidth + l_iMiddleWidth + l_iRightWidth + l_iSpacingX * 4), "General")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Process name")
g_mapControls["editProcessName"] := g_guiSettings.AddEdit("CBlack r1 x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_guiSettings.AddButton("Background" g_guiBackColor " x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " h23 w" l_iRightWidth, "Browse").OnEvent("Click",
GuiButtonBrowse_Click)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Window name")
g_mapControls["editWindowName"] := g_guiSettings.AddEdit("CBlack r1 x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_guiSettings.AddButton("Background" g_guiBackColor " x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " h23 w" l_iRightWidth, "Select").OnEvent("Click",
GuiButtonSelect_Click)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Autofire key interval")
g_mapControls["editAutofireKeyInterval"] := g_guiSettings.AddEdit("CBlack Number x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["udAutofireKeyInterval"] := g_guiSettings.AddUpDown("Range1-10000 0x80")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Focus check interval")
g_mapControls["editFocusCheckInterval"] := g_guiSettings.AddEdit("CBlack Number x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["udFocusCheckInterval"] := g_guiSettings.AddUpDown("Range1-10000 0x80")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Hook delay")
g_mapControls["editHookDelay"] := g_guiSettings.AddEdit("CBlack Number x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["udHookDelay"] := g_guiSettings.AddUpDown("Range0-10000 0x80")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Press duration")
g_mapControls["editPressDuration"] := g_guiSettings.AddEdit("CBlack Number x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["udPressDuration"] := g_guiSettings.AddUpDown("Range0-1000 0x80")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Notifications")
g_mapControls["ddlNotifications"] := g_guiSettings.AddDropDownList("x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth, l_arrNotificationTypes)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Send mode")
g_mapControls["ddlSendMode"] := g_guiSettings.AddDropDownList("x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth, l_arrSendModes)
; Key modes
l_iTopY += 7
g_guiSettings.AddGroupBox("x" l_iLeftX - 5 " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " h" 4*31 " w" (l_iLeftWidth + l_iMiddleWidth + l_iRightWidth + (l_iSpacingX * 4)),
"Key modes")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Aim")
g_mapControls["ddlAimMode"] := g_guiSettings.AddDropDownList("x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth, l_arrKeyModes)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Crouch")
g_mapControls["ddlCrouchMode"] := g_guiSettings.AddDropDownList("x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth, l_arrKeyModes)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Sprint")
g_mapControls["ddlSprintMode"] := g_guiSettings.AddDropDownList("x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth, l_arrKeyModes)
g_mapControls["cbAutorun"] := g_guiSettings.AddCheckBox("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth + 23, "Autorun ")
; Hotkeys
g_guiSettings.AddGroupBox("x" l_iLeftX - 5 " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " h" 9*28 + 3 " w" (l_iLeftWidth + l_iMiddleWidth + l_iRightWidth + (l_iSpacingX * 4)),
"Hotkeys")
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Aim")
g_mapControls["hkAimKey"] := g_guiSettings.AddHotkey("vhkAimKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlAimKey"] := g_guiSettings.AddDropDownList("vddlAimKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth, l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Crouch")
g_mapControls["hkCrouchKey"] := g_guiSettings.AddHotkey("vhkCrouchKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlCrouchKey"] := g_guiSettings.AddDropDownList("vddlCrouchKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth, l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Sprint")
g_mapControls["hkSprintKey"] := g_guiSettings.AddHotkey("vhkSprintKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlSprintKey"] := g_guiSettings.AddDropDownList("vddlSprintKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth, l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Autorun")
g_mapControls["hkAutorunKey"] := g_guiSettings.AddHotkey("vhkAutorunKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlAutorunKey"] := g_guiSettings.AddDropDownList("vddlAutorunKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth, l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Forward")
g_mapControls["hkForwardKey"] := g_guiSettings.AddHotkey("vhkForwardKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlForwardKey"] := g_guiSettings.AddDropDownList("vddlForwardKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth, l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Backward")
g_mapControls["hkBackwardKey"] := g_guiSettings.AddHotkey("vhkBackwardKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlBackwardKey"] := g_guiSettings.AddDropDownList("vddlBackwardKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth,
l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Aim autofire")
g_mapControls["hkAimAutofireKey"] := g_guiSettings.AddHotkey("vhkAimAutofireKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlAimAutofireKey"] := g_guiSettings.AddDropDownList("vddlAimAutofireKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth,
l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Crouch autofire")
g_mapControls["hkCrouchAutofireKey"] := g_guiSettings.AddHotkey("vhkCrouchAutofireKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlCrouchAutofireKey"] := g_guiSettings.AddDropDownList("vddlCrouchAutofireKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth,
l_arrExtraKeys)
g_guiSettings.AddText("Right x" l_iLeftX " y" l_iTopY + l_iSpacingY * ++l_iCurrentRow " w" l_iLeftWidth, "Sprint autofire")
g_mapControls["hkSprintAutofireKey"] := g_guiSettings.AddHotkey("vhkSprintAutofireKey x" l_iMiddleX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iMiddleWidth)
g_mapControls["ddlSprintAutofireKey"] := g_guiSettings.AddDropDownList("vddlSprintAutofireKey x" l_iRightX " y" l_iTopY + l_iSpacingY * l_iCurrentRow - 5 " w" l_iRightWidth,
l_arrExtraKeys)
g_guiSettings.AddButton("Background" g_guiBackColor " x150 y" l_iTopY + l_iSpacingY * ++l_iCurrentRow + 15 " w100", "Reset defaults").OnEvent("Click", GuiButtonResetDefaults_Click)
g_guiSettings.AddButton("Background" g_guiBackColor " x270 y" l_iTopY + l_iSpacingY * l_iCurrentRow + 15 " w100", "Save").OnEvent("Click", GuiButtonSave_Click)
; Event handlers
for l_guiCtrl in g_guiSettings
{
switch l_guiCtrl.Type
{
case "CheckBox":
l_guiCtrl.OnEvent("Click", GuiCB_Click)
case "DDL":
l_guiCtrl.OnEvent("Change", GuiDDL_Change)
case "Edit":
l_guiCtrl.OnEvent("Change", GuiEdit_Change)
case "Hotkey":
l_guiCtrl.OnEvent("Change", GuiHK_Change)
}
}
GuiUpdate()
}
; Set hotkey controls text based on selected DDL extra keys
GuiDDL_Change(p_guiCtrl, *)
{
switch p_guiCtrl
{
case g_mapControls["ddlAimMode"], g_mapControls["ddlCrouchMode"], g_mapControls["ddlSprintMode"]:
g_mapControls["hkAimKey"].Enabled := g_mapControls["ddlAimKey"].Enabled := g_mapControls["ddlAimMode"].Value > KEY_MODE_TOGGLE
g_mapControls["hkCrouchKey"].Enabled := g_mapControls["ddlCrouchKey"].Enabled := g_mapControls["ddlCrouchMode"].Value > KEY_MODE_TOGGLE
g_mapControls["hkSprintKey"].Enabled := g_mapControls["ddlSprintKey"].Enabled := g_mapControls["ddlSprintMode"].Value > KEY_MODE_TOGGLE
g_mapControls["hkAimAutofireKey"].Enabled := g_mapControls["ddlAimAutofireKey"].Enabled := g_mapControls["ddlAimMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapControls["hkCrouchAutofireKey"].Enabled := g_mapControls["ddlCrouchAutofireKey"].Enabled := g_mapControls["ddlCrouchMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapControls["hkSprintAutofireKey"].Enabled := g_mapControls["ddlSprintAutofireKey"].Enabled := g_mapControls["ddlSprintMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapSettings["iAimMode"] := g_mapControls["ddlAimMode"].Value - 1
g_mapSettings["iCrouchMode"] := g_mapControls["ddlCrouchMode"].Value - 1
g_mapSettings["iSprintMode"] := g_mapControls["ddlSprintMode"].Value - 1
case g_mapControls["ddlAimAutofireKey"], g_mapControls["ddlAimKey"], g_mapControls["ddlAutorunKey"], g_mapControls["ddlBackwardKey"], g_mapControls["ddlCrouchAutofireKey"],
g_mapControls["ddlCrouchKey"], g_mapControls["ddlForwardKey"], g_mapControls["ddlSprintAutofireKey"], g_mapControls["ddlSprintKey"]:
; Set the corresponding hotkey control's text to the selected DDL value
l_sHkControlName := StrReplace(p_guiCtrl.Name, "ddl", "hk", , , 1)
l_hkControl := g_mapControls[l_sHkControlName]
l_hkControl.Value := p_guiCtrl.Value == 1 ? "" : p_guiCtrl.Text
case g_mapControls["ddlNotifications"]:
g_mapSettings["iShowNotifications"] := g_mapControls["ddlNotifications"].Value - 1
case g_mapControls["ddlSendMode"]:
g_mapSettings["iSendMode"] := g_mapControls["ddlSendMode"].Text
SendMode(g_mapControls["ddlSendMode"].Text)
}
}
; Prevent intervals from being out-of-bounds, otherwise timers won't work
GuiEdit_Change(p_guiCtrl, *)
{
switch p_guiCtrl
{
case g_mapControls["editAutofireKeyInterval"]:
l_iMinValue := 1
l_iMaxValue := 10000
l_udControl := g_mapControls["udAutofireKeyInterval"]
case g_mapControls["editFocusCheckInterval"]:
l_iMinValue := 1
l_iMaxValue := 10000
l_udControl := g_mapControls["udFocusCheckInterval"]
case g_mapControls["editHookDelay"]:
l_iMinValue := 0
l_iMaxValue := 10000
l_udControl := g_mapControls["udHookDelay"]
case g_mapControls["editPressDuration"]:
l_iMinValue := 0
l_iMaxValue := 1000
l_udControl := g_mapControls["udPressDuration"]
SetKeyDelay(, g_mapSettings["iPressDuration"], A_SendMode == "Play" || A_SendMode == "InputThenPlay" ? "Play" : "")
default:
return
}
if (!p_guiCtrl.Value)
p_guiCtrl.Text := l_iMinValue
else
{
l_iValue := Integer(p_guiCtrl.Value)
; The UpDown control will automatically clamp the value within its range
if (l_iValue < l_iMinValue || l_iValue > l_iMaxValue)
l_udControl.Value := l_iValue
}
}
; Prevent modified keys from being used in hotkey controls (could be changed to allow them in the future)
GuiHK_Change(p_guiCtrl, *)
{
l_sHotkeyLength := StrLen(p_guiCtrl.Value)
l_bShift := InStr(p_guiCtrl.Value, "+") != 0
l_bControl := InStr(p_guiCtrl.Value, "^") != 0
l_bAlt := InStr(p_guiCtrl.Value, "!") != 0
Output("l_sHotkey(" p_guiCtrl.Value ") l_bShift(" l_bShift ") l_bControl(" l_bControl ") l_bAlt(" l_bAlt ")")
if (l_bShift && !l_bControl && !l_bAlt && l_sHotkeyLength == 1)
p_guiCtrl.Value := "LShift"
else if (!l_bShift && l_bControl && !l_bAlt && l_sHotkeyLength == 1)
p_guiCtrl.Value := "LControl"
else if (!l_bShift && !l_bControl && l_bAlt && l_sHotkeyLength == 1)
p_guiCtrl.Value := "LAlt"
else if (l_bShift || l_bControl || l_bAlt && l_sHotkeyLength > 1)
{
p_guiCtrl.Value := ""
MsgBox("You can't use modified keys!", , "Icon! Owner" g_guiSettings.Hwnd)
return
}
; Clear the corresponding DDL control if a hotkey is set
l_sDDLControlName := StrReplace(p_guiCtrl.Name, "hk", "ddl", , , 1)
g_mapControls[l_sDDLControlName].Choose(1)
}
GuiLogCreate()
{
; Safety check
if IsSet(g_guiLog)
return
global g_guiLog := Gui.Call("Owner" g_guiSettings.Hwnd " -MinimizeBox -MaximizeBox", "Log Viewer")
g_guiLog.BackColor := g_guiBackColor
g_guiLog.SetFont("s10 " g_guiTextColor)
g_mapControls["editLog"] := g_guiLog.AddEdit((g_mapSettings["bDarkMode"] ? "Background" g_guiBackColor : "cBlack") " ReadOnly -Tabstop r25 w600")
g_mapControls["editLog"].OnEvent("LoseFocus", (*) => GuiLogScrollToBottom())
g_guiLog.AddButton("Background" g_guiBackColor " x295 y425 w100", "Open file").OnEvent("Click", (*) => Run(g_sLogFileName))
g_guiLog.AddButton("Background" g_guiBackColor " x405 y425 w100", "Copy").OnEvent("Click", (*) => ShowNotification("Text copied to clipboard!") A_Clipboard := g_mapControls["editLog"].Text)
g_guiLog.AddButton("Background" g_guiBackColor " x515 y425 w100", "Clear").OnEvent("Click", (*) => g_mapControls["editLog"].Text := "")
}
GuiLogScrollToBottom()
{
; Back up previous settings
l_iPressDuration := InStr(A_SendMode, "Play") ? A_KeyDurationPlay : A_KeyDuration
l_sSendMode := A_SendMode == "Play" || A_SendMode == "InputThenPlay" ? "Play" : ""
SetKeyDelay(, 10, '')
ControlSend("^{End}", g_mapControls["editLog"])
; Restore previous settings
SetKeyDelay(, l_iPressDuration, l_sSendMode)
}
GuiLV_DoubleClick(p_guiCtrl, p_iPosItem)
{
; Reenable the main window
g_guiSettings.Opt("-Disabled")
g_guiWindowSelector.Show("Hide")
; Retrieve the text from the selected row in the ListView
l_sItemText := p_guiCtrl.GetText(p_iPosItem)
l_arr := StrSplit(l_sItemText, " | ", , 2)
; Update controls in the main window
g_mapControls["editProcessName"].Text := l_arr[1]
g_mapControls["editWindowName"].Text := l_arr.Length > 1 ? l_arr[2] : ""
}
GuiLV_ReloadProcesses()
{
; Get a list of all windows
l_arrHwnds := WinGetList()
l_arrHwndsLength := l_arrHwnds.Length
; Create an ImageList to hold large icons and assign it to the ListView
g_mapControls["ilWindowPicker"] := IL_Create(l_arrHwndsLength, , true)
l_ilPrev := g_mapControls["lvWindowPicker"].SetImageList(g_mapControls["ilWindowPicker"])
; Free up memory used by the previous ImageList
if (l_ilPrev)
IL_Destroy(l_ilPrev)
; Don't redraw until all the rows are added
g_mapControls["lvWindowPicker"].Opt("-Redraw")
; Delete all rows
g_mapControls["lvWindowPicker"].Delete()
; Create all rows
for l_hwnd in l_arrHwnds
{
try
{
; Retrieve process info
l_sProcName := WinGetProcessName("ahk_id" l_hwnd)
l_sProcPath := WinGetProcessPath("ahk_id" l_hwnd)
;l_sWinClass := WinGetClass("ahk_id" l_hwnd)
l_sWinTitle := WinGetTitle("ahk_id" l_hwnd)
; Skip this iteration if the process is in the exclusion list
if (g_mapControls["cbExcludeProcesses"].Value && IsCommonProcess(l_sProcName))
continue
/*
Output("process: " l_sProcName)
Output("path: " l_sProcPath)
Output("title: " l_sWinTitle)
Output("class: " l_sWinClass, true)
*/
g_mapControls["lvWindowPicker"].Add("Icon" IL_Add(g_mapControls["ilWindowPicker"], l_sProcPath), l_sProcName (l_sWinTitle ? " | " l_sWinTitle : ""))
}
}
g_mapControls["lvWindowPicker"].Opt("+Redraw")
}
GuiMenuHandler(p_sItemName, p_iItemPos, p_menu)
{
switch p_menu
{
case g_mapMenus["File"]:
switch p_sItemName
{
case "Save and exit":
ExitApp(1)
case "Exit":
ExitApp()
}
case g_mapMenus["View"]:
switch p_sItemName
{
case "Always on top":
g_mapSettings["bAlwaysOnTop"] := !g_mapSettings["bAlwaysOnTop"]
WinSetAlwaysOnTop(-1, 'A')
case "Close to tray":
g_mapSettings["bCloseToTray"] := !g_mapSettings["bCloseToTray"]
case "Dark mode":
g_mapSettings["bDarkMode"] := !g_mapSettings["bDarkMode"]
; Avoid showing the MsgBox multiple times
if (!States.bThemePopupShown)
{
States.bThemePopupShown := true
MsgBox("Please restart the script to apply the new theme.", , "Icon! Owner" g_guiSettings.Hwnd)
}
case "Hide window selector from capture":
g_mapSettings["bHideFromCapture"] := !g_mapSettings["bHideFromCapture"]
case "Minimize to tray":
g_mapSettings["bMinimizeToTray"] := !g_mapSettings["bMinimizeToTray"]
case "Remember window positions":
g_mapSettings["bRememberWindowPositions"] := !g_mapSettings["bRememberWindowPositions"]
}
p_menu.ToggleCheck(p_sItemName)
; We save the changes immediately to avoid having to hit Save
try
{
IniWrite(g_mapSettings["bAlwaysOnTop"], g_sConfigFileName, "UI", "alwaysOnTop")
IniWrite(g_mapSettings["bCloseToTray"], g_sConfigFileName, "UI", "closeToTray")
IniWrite(g_mapSettings["bDarkMode"], g_sConfigFileName, "UI", "darkMode")
IniWrite(g_mapSettings["bHideFromCapture"], g_sConfigFileName, "UI", "hideFromCapture")
IniWrite(g_mapSettings["bMinimizeToTray"], g_sConfigFileName, "UI", "minimizeToTray")
IniWrite(g_mapSettings["bRememberWindowPositions"], g_sConfigFileName, "UI", "rememberWindowPositions")
}
catch as e
MsgBox(Format("{1}: {2}.`n`nFile:`t{3}`nLine:`t{4}`nWhat:`t{5}`nStack:`n{6}", type(e), e.Message, e.File, e.Line, e.What, e.Stack), , "Icon! Owner" g_guiSettings.Hwnd)
case g_mapMenus["Misc"]:
switch p_sItemName
{
case "Beep on suspend":
g_mapSettings["bBeepOnSuspend"] := !g_mapSettings["bBeepOnSuspend"]
case "Enable logging":
g_mapSettings["bLog"] := !g_mapSettings["bLog"]
case "Fix system keys":
g_mapSettings["bFixSystemKeys"] := !g_mapSettings["bFixSystemKeys"]
case "Restore autofires on focus":
g_mapSettings["bRestoreAutofiresOnFocus"] := !g_mapSettings["bRestoreAutofiresOnFocus"]
case "Restore toggles on focus":
g_mapSettings["bRestoreTogglesOnFocus"] := !g_mapSettings["bRestoreTogglesOnFocus"]
case "Run as admin":
g_mapSettings["bRunAsAdmin"] := !g_mapSettings["bRunAsAdmin"]
}
p_menu.ToggleCheck(p_sItemName)
; We save the changes immediately to avoid having to hit Save
try
{
IniWrite(g_mapSettings["bFixSystemKeys"], g_sConfigFileName, "General", "fixSystemKeys")
IniWrite(g_mapSettings["bRestoreAutofiresOnFocus"], g_sConfigFileName, "General", "restoreAutofiresOnFocus")
IniWrite(g_mapSettings["bRestoreTogglesOnFocus"], g_sConfigFileName, "General", "restoreTogglesOnFocus")
IniWrite(g_mapSettings["bRunAsAdmin"], g_sConfigFileName, "General", "runAsAdmin")
IniWrite(g_mapSettings["bLog"], g_sConfigFileName, "Debug", "log")
}
catch as e
MsgBox(Format("{1}: {2}.`n`nFile:`t{3}`nLine:`t{4}`nWhat:`t{5}`nStack:`n{6}", type(e), e.Message, e.File, e.Line, e.What, e.Stack), , "Icon! Owner" g_guiSettings.Hwnd)
case g_mapMenus["Help"]:
switch p_sItemName
{
case "View log":
; Fill the edit log control with everything that has been logged before the creation of the log Gui object
if (g_mapSettings["bLog"] && !g_mapControls["editLog"].Text && !States.bPreviousLogMessagesAdded)
{
EditPaste(FileRead(g_sLogFileName), g_mapControls["editLog"], "ahk_id " g_guiLog.Hwnd)
States.bPreviousLogMessagesAdded := true
}
if !WinExist("ahk_id " g_guiLog.Hwnd)
g_guiLog.Show(g_mapSettings["bRememberWindowPositions"] ? "x" g_mapSettings["iLogWindowX"] " y" g_mapSettings["iLogWindowY"] : "")
case "Visit website":
Run("https://github.com/GenesisFR/KeyToggles")
case "About":
GuiShowAbout()
}
}
}
GuiMenuUpdate()
{
; We have to uncheck all toggleable menu items since there's no way to know which one was checked
g_mapMenus["View"].Uncheck("Always on top")
g_mapMenus["View"].Uncheck("Close to tray")
g_mapMenus["View"].Uncheck("Dark mode")
g_mapMenus["View"].Uncheck("Hide window selector from capture")
g_mapMenus["View"].Uncheck("Minimize to tray")
g_mapMenus["View"].Uncheck("Remember window positions")
g_mapMenus["Misc"].Uncheck("Beep on suspend")
g_mapMenus["Misc"].Uncheck("Enable logging")
g_mapMenus["Misc"].Uncheck("Fix system keys")
g_mapMenus["Misc"].Uncheck("Restore autofires on focus")
g_mapMenus["Misc"].Uncheck("Restore toggles on focus")
g_mapMenus["Misc"].Uncheck("Run as admin")
if (g_mapSettings["bAlwaysOnTop"])
g_mapMenus["View"].Check("Always on top")
if (g_mapSettings["bCloseToTray"])
g_mapMenus["View"].Check("Close to tray")
if (g_mapSettings["bDarkMode"])
g_mapMenus["View"].Check("Dark mode")
if (g_mapSettings["bHideFromCapture"])
g_mapMenus["View"].Check("Hide window selector from capture")
if (g_mapSettings["bMinimizeToTray"])
g_mapMenus["View"].Check("Minimize to tray")
if (g_mapSettings["bRememberWindowPositions"])
g_mapMenus["View"].Check("Remember window positions")
if (g_mapSettings["bBeepOnSuspend"])
g_mapMenus["Misc"].Check("Beep on suspend")
if (g_mapSettings["bLog"])
g_mapMenus["Misc"].Check("Enable logging")
if (g_mapSettings["bFixSystemKeys"])
g_mapMenus["Misc"].Check("Fix system keys")
if (g_mapSettings["bRestoreAutofiresOnFocus"])
g_mapMenus["Misc"].Check("Restore autofires on focus")
if (g_mapSettings["bRestoreTogglesOnFocus"])
g_mapMenus["Misc"].Check("Restore toggles on focus")
if (g_mapSettings["bRunAsAdmin"])
g_mapMenus["Misc"].Check("Run as admin")
}
GuiOnSize(p_guiCtrl, p_iMinMax, *)
{
switch p_guiCtrl
{
case g_guiSettings:
if (p_iMinMax == -1 && g_mapSettings["bMinimizeToTray"])
g_guiSettings.Hide()
}
}
GuiShowAbout(*)
{
MsgBox(
"KeyToggles v2.5`n"
"Author: Genesis`n",
"About",
"Iconi Owner" g_guiSettings.Hwnd
)
}
GuiShowMain(*)
{
g_guiSettings.Show(g_mapSettings["bRememberWindowPositions"] ? "x" g_mapSettings["iMainWindowX"] " y" g_mapSettings["iMainWindowY"] : "")
}
; Update main window controls based on current settings
GuiUpdate()
{
; Update control values
g_mapControls["cbAutorun"].Value := g_mapSettings["bAutorunMode"]
g_mapControls["ddlAimAutofireKey"].Text := IsExtraOption(g_mapSettings["sAimAutofireKey"]) ? g_mapSettings["sAimAutofireKey"] : "None"
g_mapControls["ddlAimKey"].Text := IsExtraOption(g_mapSettings["sAimKey"]) ? g_mapSettings["sAimKey"] : "None"
g_mapControls["ddlAimMode"].Value := g_mapSettings["iAimMode"] + 1
g_mapControls["ddlAutorunKey"].Text := IsExtraOption(g_mapSettings["sAutorunKey"]) ? g_mapSettings["sAutorunKey"] : "None"
g_mapControls["ddlBackwardKey"].Text := IsExtraOption(g_mapSettings["sBackwardKey"]) ? g_mapSettings["sBackwardKey"] : "None"
g_mapControls["ddlCrouchAutofireKey"].Text := IsExtraOption(g_mapSettings["sCrouchAutofireKey"]) ? g_mapSettings["sCrouchAutofireKey"] : "None"
g_mapControls["ddlCrouchKey"].Text := IsExtraOption(g_mapSettings["sCrouchKey"]) ? g_mapSettings["sCrouchKey"] : "None"
g_mapControls["ddlCrouchMode"].Value := g_mapSettings["iCrouchMode"] + 1
g_mapControls["ddlForwardKey"].Text := IsExtraOption(g_mapSettings["sForwardKey"]) ? g_mapSettings["sForwardKey"] : "None"
g_mapControls["ddlNotifications"].Value := g_mapSettings["iShowNotifications"] + 1
g_mapControls["ddlSendMode"].Value := g_mapSettings["iSendMode"] + 1
g_mapControls["ddlSprintAutofireKey"].Text := IsExtraOption(g_mapSettings["sSprintAutofireKey"]) ? g_mapSettings["sSprintAutofireKey"] : "None"
g_mapControls["ddlSprintKey"].Text := IsExtraOption(g_mapSettings["sSprintKey"]) ? g_mapSettings["sSprintKey"] : "None"
g_mapControls["ddlSprintMode"].Value := g_mapSettings["iSprintMode"] + 1
g_mapControls["editProcessName"].Value := g_mapSettings["sProcessName"]
g_mapControls["editWindowName"].Value := g_mapSettings["sWindowName"]
g_mapControls["hkAimAutofireKey"].Value := g_mapSettings["sAimAutofireKey"]
g_mapControls["hkAimKey"].Value := g_mapSettings["sAimKey"]
g_mapControls["hkAutorunKey"].Value := g_mapSettings["sAutorunKey"]
g_mapControls["hkBackwardKey"].Value := g_mapSettings["sBackwardKey"]
g_mapControls["hkCrouchAutofireKey"].Value := g_mapSettings["sCrouchAutofireKey"]
g_mapControls["hkCrouchKey"].Value := g_mapSettings["sCrouchKey"]
g_mapControls["hkForwardKey"].Value := g_mapSettings["sForwardKey"]
g_mapControls["hkSprintAutofireKey"].Value := g_mapSettings["sSprintAutofireKey"]
g_mapControls["hkSprintKey"].Value := g_mapSettings["sSprintKey"]
g_mapControls["udAutofireKeyInterval"].Value := g_mapSettings["iAutofireKeyInterval"]
g_mapControls["udFocusCheckInterval"].Value := g_mapSettings["iFocusCheckInterval"]
g_mapControls["udHookDelay"].Value := g_mapSettings["iHookDelay"]
g_mapControls["udPressDuration"].Value := g_mapSettings["iPressDuration"]
; Enable/disable controls
g_mapControls["hkAimAutofireKey"].Enabled := g_mapControls["ddlAimAutofireKey"].Enabled := g_mapControls["ddlAimMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapControls["hkAimKey"].Enabled := g_mapControls["ddlAimKey"].Enabled := g_mapControls["ddlAimMode"].Value > KEY_MODE_TOGGLE
g_mapControls["hkAutorunKey"].Enabled := g_mapControls["ddlAutorunKey"].Enabled := g_mapControls["cbAutorun"].Value
g_mapControls["hkBackwardKey"].Enabled := g_mapControls["ddlBackwardKey"].Enabled := g_mapControls["cbAutorun"].Value
g_mapControls["hkCrouchAutofireKey"].Enabled := g_mapControls["ddlCrouchAutofireKey"].Enabled := g_mapControls["ddlCrouchMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapControls["hkCrouchKey"].Enabled := g_mapControls["ddlCrouchKey"].Enabled := g_mapControls["ddlCrouchMode"].Value > KEY_MODE_TOGGLE
g_mapControls["hkForwardKey"].Enabled := g_mapControls["ddlForwardKey"].Enabled := g_mapControls["cbAutorun"].Value
g_mapControls["hkSprintAutofireKey"].Enabled := g_mapControls["ddlSprintAutofireKey"].Enabled := g_mapControls["ddlSprintMode"].Value > KEY_MODE_AUTOFIRE_TOGGLE
g_mapControls["hkSprintKey"].Enabled := g_mapControls["ddlSprintKey"].Enabled := g_mapControls["ddlSprintMode"].Value > KEY_MODE_TOGGLE
; Update always on top status
g_guiSettings.Opt((g_mapSettings["bAlwaysOnTop"] ? "+" : "-") "AlwaysOnTop")
}
IniReadType(p_sFile, p_sSection, p_sKey, p_sDefault, p_sType)
{
l_sValue := IniRead(p_sFile, p_sSection, p_sKey, p_sDefault)
switch p_sType
{
case "int":
try
{
l_iValue := l_sValue + 0
return Max(0, l_iValue) ; no negative integer
}
catch TypeError ; not an integer
{
return p_sDefault
}
case "keyMode":
try
{
l_iValue := l_sValue + 0
return (l_iValue >= KEY_MODE_DISABLED && l_iValue <= KEY_MODE_AUTOFIRE_HOLD) ? l_iValue : p_sDefault
}
catch TypeError ; not an integer
{
return p_sDefault
}
case "sendMode":
try
{
l_iValue := l_sValue + 0
return (l_iValue >= SEND_MODE_EVENT && l_iValue <= SEND_MODE_INPUTTHENPLAY) ? l_iValue : p_sDefault
}
catch TypeError ; not an integer
{
return p_sDefault
}
default:
return l_sValue
}
}
Init()
{
OnExit(OnExitCallback)
OnMessage(WM_MOUSEMOVE := 0x200, OnMouseMove)
ReadConfigFile()
RestartAsAdminIfNeeded()
FileEncoding("UTF-8")
try FileDelete(g_sLogFileName)
GuiApplyTheme()
GuiCreate()
GuiAddMenus()
GuiLogCreate()
SendMode(g_mapControls["ddlSendMode"].Text)
SetKeyDelay(, g_mapSettings["iPressDuration"], A_SendMode == "Play" || A_SendMode == "InputThenPlay" ? "Play" : "")
A_TrayMenu.Insert("&Suspend Hotkeys", "&Settings", GuiShowMain)
l_iMenuItemCount := DllCall("GetMenuItemCount", "ptr", A_TrayMenu.Handle)
A_TrayMenu.Insert(l_iMenuItemCount "&", "About", GuiShowAbout)
A_TrayMenu.ClickCount := 1
A_TrayMenu.Default := "&Settings"
StartFocusCheck()
}
IsCommonProcess(p_sProcessName)
{
l_sCommonProcesses := "
( Join| ; AHK | Game launchers | Misc | Web browsers | Windows
autohotkey.exe|autohotkey32.exe|autohotkey64.exe|autohotkeyux.exe|keytoggles.exe
amazon games ui.exe|battle.net launcher.exe|eadesktop.exe|epicgameslauncher.exe|galaxyclient.exe|launcher.exe|steam.exe|steamwebhelper.exe|upc.exe
7zfm.exe|discord.exe|msiafterburner.exe|notepad++.exe|nvcplui.exe|obs.exe|obs64.exe|rtss.exe|vlc.exe|winamp.exe|winrar.exe|wmplayer.exe
brave.exe|chrome.exe|firefox.exe|iexplore.exe|msedge.exe|opera.exe|safari.exe
applicationframehost.exe|calc.exe|cmd.exe|control.exe|explorer.exe|eventvwr.exe|hh.exe|notepad.exe|mspaint.exe|powershell.exe|regedit.exe
rundll32.exe|svchost.exe|taskmgr.exe|windowsterminal.exe
)"
; https://www.autohotkey.com/docs/v2/lib/If.htm#ExIfInContains
return StrLower(p_sProcessName) ~= l_sCommonProcesses
}
IsExtraOption(p_sKey)
{
; https://www.autohotkey.com/docs/v2/lib/If.htm#ExIfInContains
return StrLower(p_sKey) ~= "i)\A(lbutton|mbutton|rbutton|xbutton1|xbutton2|space|tab|enter|backspace)\z"
}
IsMouseButton(p_sKey)
{
; https://www.autohotkey.com/docs/v2/lib/If.htm#ExIfInContains
return StrLower(p_sKey) ~= "i)\A(lbutton|mbutton|rbutton|xbutton1|xbutton2)\z"
}
IsMouseOver(p_sWinTitle)
{
MouseGetPos(, , &l_iWinID)
return WinExist(p_sWinTitle " ahk_id " l_iWinID)
}
IsMouseOverWindow(p_iHwnd)
{
MouseGetPos(, , &l_iMouseWindowID)
return p_iHwnd == l_iMouseWindowID
}
IsProcessNameValid(p_sProcessName)
{
p_sProcessName := Trim(p_sProcessName)
if (!p_sProcessName)
return -1
SplitPath(p_sProcessName, , , &l_sExt)
return l_sExt == "exe"
}
IsWindowVisible(p_hwnd)
{
return DllCall("IsWindowVisible", "Ptr", p_hwnd)
}
KeyAutofire(p_sAutofireKey)
{
Output(A_ThisFunc "::begin")
switch p_sAutofireKey
{
case g_mapSettings["sAimAutofireKey"]:
SendKey(g_mapSettings["sAimKey"], g_mapSettings["iPressDuration"])
case g_mapSettings["sCrouchAutofireKey"]:
SendKey(g_mapSettings["sCrouchKey"], g_mapSettings["iPressDuration"])
case g_mapSettings["sSprintAutofireKey"]:
SendKey(g_mapSettings["sSprintKey"], g_mapSettings["iPressDuration"])
}
Output(A_ThisFunc "::end")
}
KeyHold(p_sKey)
{
;Output(A_ThisFunc "::begin")
SendKey(p_sKey, g_mapSettings["iPressDuration"])
KeyWait(p_sKey)
SendKey(p_sKey, g_mapSettings["iPressDuration"])
;Output(A_ThisFunc "::end")
}
KeyToggle(p_sKey, p_bToggle, p_bWait := false)
{
Output(A_ThisFunc "::begin")
switch p_sKey
{
case g_mapSettings["sAimKey"]:
g_mapStates["bAiming"] := p_bToggle
case g_mapSettings["sCrouchKey"]:
g_mapStates["bCrouching"] := p_bToggle
case g_mapSettings["sSprintKey"]:
g_mapStates["bSprinting"] := p_bToggle
case g_mapSettings["sForwardKey"]:
g_mapStates["bAutorunning"] := p_bToggle