-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFireKey2.au3
More file actions
1525 lines (1343 loc) · 61.5 KB
/
FireKey2.au3
File metadata and controls
1525 lines (1343 loc) · 61.5 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
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=1_firekey.ico
#AutoIt3Wrapper_Outfile=FireKey2 (x86).exe
#AutoIt3Wrapper_Outfile_x64=FireKey2.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=Manage your computer with hotkeys
#AutoIt3Wrapper_Res_Description=FireKey2
#AutoIt3Wrapper_Res_Fileversion=2.2.2.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_Icon_Add=5_editor.ico
#AutoIt3Wrapper_Res_Icon_Add=6_keyboard.ico
#AutoIt3Wrapper_Res_Icon_Add=7_windows.ico
#AutoIt3Wrapper_Res_Icon_Add=8_power.ico
#AutoIt3Wrapper_Res_Icon_Add=9_volume.ico
#AutoIt3Wrapper_Res_Icon_Add=10_autoit.ico
#AutoIt3Wrapper_Res_Icon_Add=11_autoitline.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
--- Version history ---
2.2.2.0 - Github Release
2.2.1.4 - Fixed WM_CONTEXTMENU to only apply to listview.
2.2.1.3 - Changed "Execute" context menu option to "Test".
2.2.1.0 - Fixed "Run As Admin" option in run command (previously unimplemented).
....... - Fixed "Disable Key" size (wasn't big enough)
....... - Fixed "No Tray Icon" option for main program (was ignoring the option).
....... - Fixed window size memory and added option to enable/disable.
2.2.0.5 - Changed config directory.
2.2.0.4 - Set minimum window size for Add/Edit window.
....... - Fixed "Disable key" checkbox movement (sticks to bottom of window now).
....... - Removed cmd line param for source since it's provided in a menu option.
2.2.0.3 - Removed tooltip on file run.
....... - Changed priority magic numbers to $PROCESS_* constants.
2.2.0.2 - Red color for disabled hotkeys.
....... - Changed item details for in-use hotkeys.
2.2.0.1 - Removed 64 bit auto-run.
....... - Changed compiled names: 32 bit is now "FireKey (x86).exe" and 64 bit is "FireKey.exe".
2.2.0.0 - Added disable key option.
....... - Added accelerators to key list context menu.
2.1.1.0 - Fixed bug with saving/restoring window position.
....... - Changed window fade function from DllCall to UDF.
2.1.0.7 - Rearranged Options menu.
2.1.0.6 - AutoIt line now has a full edit box (merged to single line on execution).
....... - Main window size/pos is now remembered.
....... - Listview is focused after key add/edit.
....... - Default sort keys in order of creation/update.
2.1.0.5 - Changes to _FileGetIcon, added new icons for "AutoIt commands".
2.1.0.4 - Fixed double click working in listview.
2.1.0.3 - Added context menu trigger for listview using WM_CONTEXTMENU (For Shift+F10).
#ce
#pragma compile(AutoItExecuteAllowed, true)
#region - Includes
Opt('MustDeclareVars', 1)
Opt('GUIDataSeparatorChar', @CR)
; Standard AutoIt includes
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIListView.au3>
#include <GUIMenu.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <File.au3>
; My personal includes
#include <vkConstants.au3>
#include <_FileGetIcon().au3>
#include <_MySingleton().au3>
#include <_WinFade().au3>
; Application specific includes
#include "_Yashied_HotKey_21b.au3"
#include "_HotKey_Mod_Yashied.au3"
#include "_SoundGetSetQuery.au3"
#include "_AudioEndpointVolume.au3"
#endregion
#region - Constants required for prechecks
Global Const $APP_NAME = 'FireKey2'
Global Const $FK_INTERACT_STR = 'FIREKEY2_INTERACT'
Global Const $FK_INTERACT_MSG = _WinAPI_RegisterWindowMessage($FK_INTERACT_STR)
Global Enum $FK_MSG_OPENLIST
#endregion
#region - Run-once logic
; FireKey v1 check. If running: warn user
Global Const $sFireKey1DetectorWin = 'AutoIt3.FireKey.Window'
If WinExists($sFireKey1DetectorWin) Then
MsgBox(0x30, $APP_NAME, 'FireKey version 1 is currently running. You should exit that program before using this one.')
ControlSetText($sFireKey1DetectorWin, '', 'Edit1', 'Show Yourself')
EndIf
; FireKey 2 check. If already running open list from previous instance and exit
If Not _MySingleton($FK_INTERACT_STR, 1) Then
_SendMessage(WinGetHandle($FK_INTERACT_STR), $FK_INTERACT_MSG, $FK_MSG_OPENLIST)
Exit @ScriptLineNumber
EndIf
#endregion
#region - Constants & global vars
Global $TMP
Global Const $TRAY_DEFAULT = 512
Global $BIT_VERSION = 32
If @AutoItX64 Then $BIT_VERSION = 64
Global Const $OLD_DATA_DIR = @AppDataDir & '\' & $APP_NAME
Global Const $DATA_DIR = @AppDataDir & '\therkSoft\' & $APP_NAME
If FileExists($OLD_DATA_DIR) Then DirMove($OLD_DATA_DIR, $DATA_DIR)
DirCreate($DATA_DIR)
Global Const $STARTUP_LINK = @StartupDir & '\' & $APP_NAME & '.lnk'
Global Const $CONFIG_FILE = $DATA_DIR & '\Config.ini'
Global Const $KEY_FILE = $DATA_DIR & '\Keys.ini'
Global Const $ERROR_LOG = $DATA_DIR & '\Error Log.txt'
Global Const $README = $DATA_DIR & '\ReadMe.html'
Global Const $SOURCE = $DATA_DIR & '\Source.txt'
Global $MASTER_KEY_LIST, $KEY_LIST_REVLOOKUP[16]
Global Enum $MKL_HOTKEY, $MKL_VKEY, $MKL_DATA, $MKL_CTRLID, $MKL_UBOUND
Global Const $INI_CFG_TITLE = 'Config', $INI_CFG_SPLASH = 'Splash', $INI_CFG_TRAYICON = 'Tray', $INI_CFG_MEMWINPOS = 'MemWinPos', $INI_CFG_WINPOS = 'WinPos', _
$INI_CFG_PRIORITY = 'Priority', $INI_CFG_CONFDELETE = 'ConfDel', $INI_CFG_KEYTAKEN = 'KeyTaken', $INI_CFG_CONFEXIT = 'ConfExit', $INI_CFG_TRAYTIP = 'TrayTip', _
$INI_KEY_FUNC = 'Function', $INI_KEY_PROMPT = 'Prompt', $INI_KEY_VIRTKEY = 'IsVK', $INI_KEY_DISABLED = 'Disabled', $INI_KEY_COMMENT = 'Comment', _
$INI_KEY_PATH = 'Path', $INI_KEY_PARAMS = 'Params', $INI_KEY_WORKDIR = 'WorkDir', $INI_KEY_WINSTYLE = 'Window', $INI_KEY_RUNADMIN = 'RunAsAdmin', _
$INI_KEY_VOLADJUST = 'Adjust', $INI_KEY_VOLDISPLAY = 'Display', $INI_KEY_MUTE = 'Mute'
Global Enum $FTBL_COL_ID, $FTBL_COL_STR, $FTBL_COL_ICO, $FTBL_COL_UBOUND
Global Enum $FTBL_ROW_RUN, $FTBL_ROW_BREAK_1, _
$FTBL_ROW_VOLUME, $FTBL_ROW_BREAK_2, _
$FTBL_ROW_TOGGLEICONS, $FTBL_ROW_WINCLOSE, $FTBL_ROW_WINMIN, $FTBL_ROW_WINMAX, $FTBL_ROW_WINRESTORE, $FTBL_ROW_WINMINALL, $FTBL_ROW_WINMINALLUNDO, $FTBL_ROW_BREAK_3, _
$FTBL_ROW_MONOFF, $FTBL_ROW_LOGOFF, $FTBL_ROW_SHUTDOWN, $FTBL_ROW_REBOOT, $FTBL_ROW_SLEEP, $FTBL_ROW_HIBERNATE, $FTBL_ROW_BREAK_4, _
$FTBL_ROW_OPENLIST, $FTBL_ROW_CLOSELIST, $FTBL_ROW_TOGGLELIST, $FTBL_ROW_RELOADKEYS, $FTBL_ROW_EXITHANDLER, $FTBL_ROW_BREAK_5, _
$FTBL_ROW_AUTOIT, $FTBL_ROW_AUTOITLINE, $FTBL_ROW_UBOUND
Global Const $FUNCTIONS_TABLE[$FTBL_ROW_UBOUND][$FTBL_COL_UBOUND] = [ _
[ 'Run', 'Run' ], _
[ '' ], _
[ 'Volume', 'Volume Adjust', -9 ], _
[ '' ], _
[ 'ToggleIcons', 'Hide/Show Desktop Icons', -7 ], _
[ 'WinClose', 'Close Active Window', -7 ], _
[ 'WinMinimize', 'Minimize Active Window', -7 ], _
[ 'WinMaximize', 'Maximize Active Window', -7 ], _
[ 'WinRestore', 'Restore Active Window', -7 ], _
[ 'WinMinAll', 'Minimize All Windows', -7 ], _
[ 'WinMinAllUndo', 'Undo Minimize All Windows', -7 ], _
[ '' ], _
[ 'MonitorOff', 'Monitor to Sleep', -8 ], _
[ 'LogOff', 'Log Off User', -8 ], _
[ 'Shutdown', 'Shutdown Computer', -8 ], _
[ 'Reboot', 'Reboot Computer', -8 ], _
[ 'Sleep', 'Sleep Computer', -8 ], _
[ 'Hibernate', 'Hibernate Computer', -8 ], _
[ '' ], _
[ 'OpenList', 'Open FireKey Window', -5 ], _
[ 'CloseList', 'Close FireKey Window', -5 ], _
[ 'ToggleList', 'Toggle FireKey Window', -5 ], _
[ 'ReloadKeys', 'Reload FireKey Keys', -5 ], _
[ 'ExitHandler', 'Shutdown FireKey', -6 ], _
[ '' ], _
[ 'AutoIt', 'AutoIt3 Script', -10 ], _
[ 'AutoItLine', 'AutoIt3 Line', -11 ] _
]
Global Const $FK_WINSTYLES[4] = [ @SW_SHOW, @SW_MINIMIZE, @SW_MAXIMIZE ]
Global $g_sHotKeyAdding, $g_sHotKeyEditing, _
$g_iShowSplash = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_SPLASH, 1)), _
$g_iTrayIcon = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_TRAYICON, 1)), _
$g_iConfDelete = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_CONFDELETE, 1)), _
$g_iKeyTakenNotice = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_KEYTAKEN, 1)), _
$g_iConfExit = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_CONFEXIT, 1)), _
$g_iTrayTip = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_TRAYTIP, 1)), _
$g_iPriority = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_PRIORITY, 0)), _
$g_iWinPosMem = Int(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_MEMWINPOS, 1)), _
$g_aLaunchSize[4] = [ (@DesktopWidth - 640) / 2, (@DesktopHeight - 480) / 2, 640, 480 ], _
$g_sComboList = $FUNCTIONS_TABLE[$FTBL_ROW_RUN][$FTBL_COL_STR]
For $i = 1 To $FTBL_ROW_UBOUND-1
$g_sComboList &= @CR & $FUNCTIONS_TABLE[$i][$FTBL_COL_STR]
Next
If $g_iWinPosMem Then
$TMP = StringSplit(IniRead($CONFIG_FILE, $INI_CFG_TITLE, $INI_CFG_WINPOS, ''), '|', 2)
If UBound($TMP) = 4 Then $g_aLaunchSize = $TMP
EndIf
#endregion - Constants & global vars
#region - Splash window
Global $g_hGUISplash, $lb_Splash, $sTempIcon = $DATA_DIR & '\icon.ico'
If $g_iShowSplash = 1 Then
FileInstall('1_firekey.ico', $sTempIcon)
$g_hGUISplash = GUICreate($APP_NAME & ' - Loading...', 150, 75, Default, Default, BitOR($WS_POPUP, $WS_DLGFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUICtrlCreateIcon($sTempIcon, 0, 51, 5, 48, 48)
$lb_Splash = GUICtrlCreateLabel('Loading...', 5, 58, 140, 15, $SS_CENTER)
_WinFade($g_hGUISplash, '', @SW_SHOWNA, 500)
Sleep(500)
EndIf
#endregion - Splash window
GUICtrlSetData($lb_Splash, 'Creating message hooks')
Global Const $FK_INTERACT_HWND = GUICreate($FK_INTERACT_STR)
GUIRegisterMsg($FK_INTERACT_MSG, '_FK_INTERACT_MSG')
GUICtrlSetData($lb_Splash, 'Setup volume handler')
#region - Setup volume settings. Vista+ uses .dll plugin. Otherwise handled by script.
Global $USE_VISTA_FUNCS
If Not StringRegExp(@OSVersion, 'WIN_(2003|XP|XPe|2000)') Then $USE_VISTA_FUNCS = 1
Global $VOLUME_HWND = GUICreate('FK2VolumeDisplay', 100, 100, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xff00)
WinSetTrans($VOLUME_HWND, '', 200)
GUISetState(@SW_DISABLE)
#endregion
GUICtrlSetData($lb_Splash, 'Building interfaces')
Opt('GUIOnEventMode', 1)
Opt('GUIResizeMode', $GUI_DOCKSTATEBAR)
#region - Main List Window
Global $g_hGUIMain, $cm_ItemsMenu, $mi_MenuEdit, $mi_MenuCopy, $mi_MenuDisable, $mi_MenuDelete, $mi_MenuRun, $lv_KeyList, $bt_Add, $bt_Edit, $bt_Delete, $bt_Options, _
$cm_Options, $mi_Startup, $mi_Reload, $mi_Exit, $me_MoreOptions, $mi_Readme, $mi_Source, $mi_TrayIcon, $mi_TrayTip, $mi_Splash, $mi_ConfExit, $mi_ConfDel, _
$mi_KeyTaken, $mi_WinPosMem, $me_Priority, $mi_PriLow, $mi_PriNorm, $mi_PriHigh, $mi_Log, $mi_DataDir, $me_AdvOptions, $mi_DeleteData
$g_hGUIMain = GUICreate($APP_NAME, 400, 270, Default, Default, $WS_OVERLAPPEDWINDOW)
GUISetIcon(@AutoItExe, -5)
GUISetOnEvent($GUI_EVENT_CLOSE, '_MainHandler')
$cm_ItemsMenu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$mi_MenuEdit = GUICtrlCreateMenuItem('&Edit' &@TAB& 'Enter', $cm_ItemsMenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_MenuCopy = GUICtrlCreateMenuItem('Dupli&cate' &@TAB& 'Ctrl+C', $cm_ItemsMenu)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_MenuDisable = GUICtrlCreateMenuItem('Dis&able' &@TAB& 'Ctrl+D', $cm_ItemsMenu)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_MenuDelete = GUICtrlCreateMenuItem('&Delete' &@TAB& 'Del', $cm_ItemsMenu)
GUICtrlSetOnEvent(-1, '_MainHandler')
GUICtrlCreateMenuItem('', $cm_ItemsMenu)
$mi_MenuRun = GUICtrlCreateMenuItem('&Test' &@TAB& 'Ctrl+T', $cm_ItemsMenu)
GUICtrlSetOnEvent(-1, '_MainHandler')
$lv_KeyList = GUICtrlCreateListView('Key' &@CR& 'Function' &@CR& 'Details', 5, 5, 390, 210, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL))
GUICtrlSetOnEvent($lv_KeyList, '_MainHandler')
_GUICtrlListView_RegisterSortCallBack($lv_KeyList)
GUICtrlSetImage(-1, 'shell32.dll', 0)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$bt_Add = GUICtrlCreateButton('&Add HotKey', 5, 220, 90, 30)
GUICtrlSetFont(-1, 10)
GUICtrlSetOnEvent(-1, '_MainHandler')
$bt_Edit = GUICtrlCreateButton('&Edit HotKey', 105, 220, 90, 30)
GUICtrlSetFont(-1, 10)
GUICtrlSetOnEvent(-1, '_MainHandler')
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$bt_Delete = GUICtrlCreateButton('&Delete HotKey', 205, 220, 90, 30)
GUICtrlSetFont(-1, 10)
GUICtrlSetOnEvent(-1, '_MainHandler')
$bt_Options = GUICtrlCreateButton('&Options', 305, 220, 90, 30)
GUICtrlSetFont(-1, 10)
GUICtrlSetOnEvent(-1, '_MainHandler')
GUICtrlCreateLabel('¹ Confirm before execute. ² Using virtual key hook.', 5, 255, 390, 15, $SS_RIGHT)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM+$GUI_DOCKRIGHT)
$cm_Options = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
GUICtrlCreateMenuItem('Version ' & FileGetVersion(@ScriptFullPath) & ' ' & $BIT_VERSION & '-bit', $cm_Options)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem('', $cm_Options)
$mi_Readme = GUICtrlCreateMenuItem('&View ReadMe' &@TAB& 'F1', $cm_Options)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_Reload = GUICtrlCreateMenuItem('&Reload Keys' &@TAB& 'F5', $cm_Options)
GUICtrlSetOnEvent(-1, '_MainHandler')
$me_MoreOptions = GUICtrlCreateMenu('More &Options', $cm_Options)
$mi_Startup = GUICtrlCreateMenuItem('Run on &Login', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If FileExists($STARTUP_LINK) Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_ConfExit = GUICtrlCreateMenuItem('Confirm Sh&utdown', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iConfExit = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_ConfDel = GUICtrlCreateMenuItem('Confirm Key &Delete', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iConfDelete = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_KeyTaken = GUICtrlCreateMenuItem('Warn If Key Is &Taken', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iConfDelete = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_WinPosMem = GUICtrlCreateMenuItem('&Remember Window Size/Position', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iWinPosMem = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_TrayIcon = GUICtrlCreateMenuItem('Show Tray &Icon', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iTrayIcon = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_TrayTip = GUICtrlCreateMenuItem('Show Tray &Tip On Key Error', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iTrayTip = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$mi_Splash = GUICtrlCreateMenuItem('Show &Splash Screen', $me_MoreOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
If $g_iShowSplash = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$me_Priority = GUICtrlCreateMenu('Set &Priority', $me_MoreOptions)
$mi_PriLow = GUICtrlCreateMenuItem('&Low/Idle', $me_Priority, 0, 1)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_PriNorm = GUICtrlCreateMenuItem('&Normal', $me_Priority, 1, 1)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_PriHigh = GUICtrlCreateMenuItem('&High', $me_Priority, 2, 1)
GUICtrlSetOnEvent(-1, '_MainHandler')
Switch $g_iPriority
Case 0
GUICtrlSetState($mi_PriLow, $GUI_CHECKED)
Case 2
GUICtrlSetState($mi_PriNorm, $GUI_CHECKED)
Case 4
GUICtrlSetState($mi_PriHigh, $GUI_CHECKED)
EndSwitch
GUICtrlCreateMenuItem('', $me_MoreOptions)
$me_AdvOptions = GUICtrlCreateMenu('Advanced &Options', $me_MoreOptions)
GUICtrlCreateMenuItem('AutoIt Version ' & @AutoItVersion, $me_AdvOptions)
GUICtrlSetState(-1, $GUI_DISABLE)
$mi_Source = GUICtrlCreateMenuItem('View Source &Code', $me_AdvOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
GUICtrlCreateMenuItem('', $me_AdvOptions)
$mi_Log = GUICtrlCreateMenuItem('View Error &Log', $me_AdvOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_DataDir = GUICtrlCreateMenuItem('View Data &Folder', $me_AdvOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
$mi_DeleteData = GUICtrlCreateMenuItem('Delete All FireKey Data', $me_AdvOptions)
GUICtrlSetOnEvent(-1, '_MainHandler')
GUICtrlCreateMenuItem('', $cm_Options)
$mi_Exit = GUICtrlCreateMenuItem('E&xit' &@TAB& 'Alt+X', $cm_Options)
GUICtrlSetOnEvent(-1, '_MainHandler')
Global $aMainAccel = [ [ '{f1}', $mi_Readme ], [ '{f5}', $mi_Reload ], [ '!x', $mi_Exit ], [ '^c', $mi_MenuCopy ], [ '^d', $mi_MenuDisable ], [ '^t', $mi_MenuRun ], [ '{del}', $mi_MenuDelete ] ]
GUISetAccelerators($aMainAccel)
#endregion
#region - HotKey Editor Window
Global $g_hGUIEditor, $in_Ed_HotKey, $bt_Ed_HotKeyChoose, $ch_Ed_Prompt, $ch_Ed_VirtKey, $cb_Ed_Functions, $tb_Ed_Functions, $tbi_Ed_Run, _
$tbi_Ed_AutoIt, $tbi_Ed_AutoItLine, $tbi_Ed_Volume, $tbi_Ed_Blank, $in_Ed_Path, $bt_Ed_BrFile, $bt_Ed_BrFolder, $in_Ed_Params, _
$in_Ed_WorkDir, $cb_Ed_WinStyle, $ch_Ed_RunAdmin, $in_Ed_AutoItPath, $in_Ed_AutoItParams, $in_Ed_AutoItLine, $bt_Ed_BrAutoItFile, $ra_Ed_VolAmount, _
$in_Ed_VolAdjust, $ch_Ed_VolDisplay, $ra_Ed_VolMute, $in_Ed_Comment, $ch_Ed_Disabled, $bt_Ed_OK, $bt_Ed_Cancel
$g_hGUIEditor = GUICreate('Add/Edit HotKey', 300, 255, Default, Default, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX), $WS_EX_ACCEPTFILES, $g_hGUIMain)
GUISetOnEvent($GUI_EVENT_CLOSE, '_EditHandler')
GUISetOnEvent($GUI_EVENT_DROPPED, '_EditHandler')
Opt('GUIResizeMode', $GUI_DOCKALL)
GUICtrlCreateLabel('HotKey:', 5, 5, 40, 20, $SS_CENTERIMAGE)
$in_Ed_HotKey = GUICtrlCreateInput('', 45, 5, 190, 20, BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$bt_Ed_HotKeyChoose = GUICtrlCreateButton('&Choose', 235, 5, 60, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetOnEvent(-1, '_EditHandler')
GUICtrlCreateLabel('', 5, 29, 290, 2, $SS_SUNKEN)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$ch_Ed_Prompt = GUICtrlCreateCheckbox('C&onfirm before execute.', 5, 35, 140, 15)
$ch_Ed_VirtKey = GUICtrlCreateCheckbox('Use &virtual key hook.', 145, 35, 290, 15)
GUICtrlSetTip(-1, 'Can allow some normally restricted hotkeys (ie: Win+R) but may sometimes fail to execute.')
GUICtrlCreateLabel('Choose &Function:', 5, 55, 85, 20, $SS_CENTERIMAGE)
$cb_Ed_Functions = GUICtrlCreateCombo('', 95, 55, 200, 200, $CBS_DROPDOWNLIST)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlSetData(-1, $g_sComboList)
GUICtrlSetOnEvent($cb_Ed_Functions, '_EditHandler')
$tb_Ed_Functions = GUICtrlCreateTab(-100, 1, 1, 1)
GUICtrlSetState(-1, $GUI_DISABLE)
$tbi_Ed_Run = GUICtrlCreateTabItem('-')
GUICtrlCreateGroup('', 5, 75, 290, 120)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlCreateLabel('&Path:', 15, 90, 30, 20, $SS_CENTERIMAGE)
$in_Ed_Path = GUICtrlCreateInput('', 50, 90, 195, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$bt_Ed_BrFile = GUICtrlCreateButton('', 245, 90, 20, 20, $BS_ICON)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetTip(-1, 'Browse for file...')
GUICtrlSetImage(-1, 'shell32.dll', 0, 0)
GUICtrlSetOnEvent(-1, '_EditHandler')
$bt_Ed_BrFolder = GuiCtrlCreateButton('', 265, 90, 20, 20, $BS_ICON)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetTip(-1, 'Browse for folder...')
GUICtrlSetImage(-1, 'shell32.dll', -4, 0)
GUICtrlSetOnEvent(-1, '_EditHandler')
GUICtrlCreateLabel('Pa&rameters:', 15, 115, 60, 20, $SS_CENTERIMAGE)
$in_Ed_Params = GUICtrlCreateInput('', 80, 115, 205, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlCreateLabel('Working &Dir:', 15, 140, 60, 20, $SS_CENTERIMAGE)
$in_Ed_WorkDir = GUICtrlCreateInput('', 80, 140, 205, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlCreateLabel('&Window:', 15, 165, 60, 20, $SS_CENTERIMAGE)
$cb_Ed_WinStyle = GUICtrlCreateCombo('', 80, 165, 100, 200, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, 'Normal' &@CR& 'Minimized' &@CR& 'Maximized')
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$ch_Ed_RunAdmin = GUICtrlCreateCheckbox('Run as &Admin', 190, 165, 95, 20)
GUICtrlSetTip(-1, 'Only works with executable files. Other files will produce an error.')
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
$tbi_Ed_AutoIt = GUICtrlCreateTabItem('-')
GUICtrlCreateGroup('', 5, 75, 290, 70)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlCreateLabel('&Path:', 15, 90, 30, 20, $SS_CENTERIMAGE)
$in_Ed_AutoItPath = GUICtrlCreateInput('', 50, 90, 215, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$bt_Ed_BrAutoItFile = GUICtrlCreateButton('', 265, 90, 20, 20, $BS_ICON)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetTip(-1, 'Browse for file...')
GUICtrlSetImage(-1, 'shell32.dll', 0, 0)
GUICtrlSetOnEvent(-1, '_EditHandler')
GUICtrlCreateLabel('Pa&rameters:', 15, 115, 60, 20, $SS_CENTERIMAGE)
$in_Ed_AutoItParams = GUICtrlCreateInput('', 80, 115, 205, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$tbi_Ed_AutoItLine = GUICtrlCreateTabItem('-')
GUICtrlCreateGroup('Co&de:', 5, 75, 290, 120)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$in_Ed_AutoItLine = GUICtrlCreateEdit('', 15, 90, 270, 95)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
GUICtrlSetTip(-1, 'This code will be merged to one line when executed.' & @LF & 'Make sure to end lines appropriately.', 'Notice:', 1, 1+2)
$tbi_Ed_Volume = GUICtrlCreateTabItem('-')
GUICtrlCreateGroup('', 5, 75, 290, 65)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$ra_Ed_VolAmount = GUICtrlCreateRadio('&Amount (-100 to 100):', 15, 90, 125, 20)
$in_Ed_VolAdjust = GUICtrlCreateInput('', 145, 90, 30, 20)
GUICtrlSetLimit(-1, 4)
$ch_Ed_VolDisplay = GUICtrlCreateCheckbox('D&isplay Meter', 180, 90, 85, 20)
$ra_Ed_VolMute = GUICtrlCreateRadio('&Toggle Mute', 15, 110, 85, 20)
$tbi_Ed_Blank = GUICtrlCreateTabItem('-')
GUICtrlCreateTabItem('')
GUICtrlCreateLabel('Co&mment:', 5, 200, 50, 20, $SS_CENTERIMAGE)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT))
$in_Ed_Comment = GUICtrlCreateInput('', 60, 200, 235, 20)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT))
$ch_Ed_Disabled = GUICtrlCreateCheckbox('Disable Hot&Key', 5, 225, 100, 25)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKLEFT))
$bt_Ed_OK = GUICtrlCreateButton('OK', 170, 225, 60, 25)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetState(-1, $GUI_DEFBUTTON)
GUICtrlSetOnEvent(-1, '_EditHandler')
$bt_Ed_Cancel = GUICtrlCreateButton('Cancel', 235, 225, 60, 25)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKSTATEBAR, $GUI_DOCKSIZE, $GUI_DOCKRIGHT))
GUICtrlSetOnEvent(-1, '_EditHandler')
#endregion
GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
GUIRegisterMsg($WM_CONTEXTMENU, WM_CONTEXTMENU)
GUIRegisterMsg($WM_GETMINMAXINFO, WM_GETMINMAXINFO)
GUIRegisterMsg($WM_SIZE, WM_SIZENMOVE)
GUIRegisterMsg($WM_MOVE, WM_SIZENMOVE)
Opt('TrayMenuMode', 1+2+8)
Opt('TrayOnEventMode', 1)
TraySetClick(8)
TrayCreateItem('&Open Key List')
TrayItemSetState(-1, $TRAY_DEFAULT)
TrayItemSetOnEvent(-1, '_OpenKeyList')
TrayCreateItem('E&xit')
TrayItemSetOnEvent(-1, '_ExitPrompt')
OnAutoItExitRegister('_OnExit')
GUICtrlSetData($lb_Splash, 'Loading / registering key list')
_MasterKeyLoadList()
GUICtrlSetData($lb_Splash, 'Enjoy :)')
If $g_iShowSplash = 1 Then
_WinFade($g_hGUISplash, '', @SW_HIDE, 500)
GUIDelete($g_hGUISplash)
EndIf
If $g_iTrayIcon Then
TraySetState()
_TraySetTip()
Else
_OpenKeyList()
EndIf
If Not @Compiled Then _OpenKeyList()
ProcessSetPriority(@AutoItPID, $g_iPriority)
ProcessWaitClose(@AutoItPID)
#region - Master key functions
#cs
Example usage:
$sFunctionString = _FuncLookup('WinClose') ; Returns 'Close Active Window'
$sFunctionID = _FuncLookup('Close Active Window') ; Returns 'WinClose'
#ce
Func _FuncLookup($sLookup, $bGetID = 0)
For $for = 0 To UBound($FUNCTIONS_TABLE)-1
If $bGetID And $FUNCTIONS_TABLE[$for][$FTBL_COL_STR] = $sLookup Then Return SetExtended($for, $FUNCTIONS_TABLE[$for][$FTBL_COL_ID])
If Not $bGetID And $FUNCTIONS_TABLE[$for][$FTBL_COL_ID] = $sLookup Then Return SetExtended($for, $FUNCTIONS_TABLE[$for][$FTBL_COL_STR])
Next
Return SetError(1, 0, $sLookup)
EndFunc
Func _MasterKeyLoadList()
Local $bErrorNotice
_GUICtrlListView_BeginUpdate($lv_KeyList)
_GUICtrlListView_DeleteAllItems($lv_KeyList)
If IsArray($MASTER_KEY_LIST) Then
; If the keylist is already created then HotKeys have already been set and we need to clear them
_HotKey_Release()
For $for = 1 To $MASTER_KEY_LIST[0][0]
HotKeySet($MASTER_KEY_LIST[$for][$MKL_HOTKEY])
Next
EndIf
Local $aSections = IniReadSectionNames($KEY_FILE)
If @error Then
; If the config file is empty then we'll just clear up the master list
Global $MASTER_KEY_LIST
Else
Global $MASTER_KEY_LIST[$aSections[0]+1][$MKL_UBOUND]
For $forKeyID = $aSections[0] To 1 Step -1
; Setup/reset icon and details for listview items
Local $sFunction = '', $sDetails = '', $aIcon[2], $bDisabled = False, $bKeySetError = False
$MASTER_KEY_LIST[0][0] += 1
; We changed ] char into ) because it's used for Section declarations.
$MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY] = StringReplace($aSections[$forKeyID], ')', ']')
$MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_DATA] = IniReadSection($KEY_FILE, $aSections[$forKeyID])
If _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_DISABLED) Then $bDisabled = True
If Not $bDisabled Then
If _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_VIRTKEY) Then ; If virtual key
_HotKey_Assign(_HotKeyToVirtKey($MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY]), '_MasterKeyVirtKeyFunc', $HK_FLAG_EXTENDEDCALL)
Else
$bKeySetError = Not HotKeySet($MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY], '_MasterKeyHotKeyFunc')
EndIf
EndIf
If $bKeySetError Then
_ErrorLog('Key in use: ' & _HotKeyToString($MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY]))
$bDisabled = True
$sDetails = '(Disabled: Key in use) '
$bErrorNotice = True
EndIf
; Lookup info for listview item text
$sFunction = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_FUNC)
If @error Then
$sFunction = 'Error'
$sDetails &= 'Invalid data.'
$bErrorNotice = True
EndIf
Switch $sFunction
Case 'Error'
$aIcon[0] = @AutoItExe
$aIcon[1] = -3
Case $FUNCTIONS_TABLE[$FTBL_ROW_RUN][$FTBL_COL_ID]
; If the function is Run
Local $sPath = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PATH)
Local $sParams = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PARAMS)
If $sParams Then $sParams = ' / Params: ' & $sParams
Local $sWorkDir = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_WORKDIR)
If $sWorkDir Then $sWorkDir = ' / Work dir: ' & $sWorkDir
$sDetails &= $sPath & $sWorkDir & $sParams
$aIcon = _FileGetIcon($sPath, 'shell32.dll', 0)
Case $FUNCTIONS_TABLE[$FTBL_ROW_AUTOIT][$FTBL_COL_ID]
Local $sPath = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PATH)
Local $sParams = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PARAMS)
If $sParams Then $sParams = ' / Params: ' & $sParams
$sDetails &= $sPath & $sParams
$aIcon[0] = @AutoItExe
$aIcon[1] = $FUNCTIONS_TABLE[$FTBL_ROW_AUTOIT][$FTBL_COL_ICO]
Case $FUNCTIONS_TABLE[$FTBL_ROW_AUTOITLINE][$FTBL_COL_ID]
Local $sParams = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PARAMS)
$sDetails &= StringReplace(StringStripCR(StringFormat($sParams)), '\n', '')
$aIcon[0] = @AutoItExe
$aIcon[1] = $FUNCTIONS_TABLE[$FTBL_ROW_AUTOITLINE][$FTBL_COL_ICO]
Case $FUNCTIONS_TABLE[$FTBL_ROW_VOLUME][$FTBL_COL_ID]
Local $iAdjAmount = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_VOLADJUST)
If $iAdjAmount = $INI_KEY_MUTE Then
$sDetails &= 'Toggle mute'
Else
If $iAdjAmount < 0 Then
$sDetails &= 'Lower volume ' & -$iAdjAmount & '%'
Else
$sDetails &= 'Raise volume ' & $iAdjAmount & '%'
EndIf
If _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_VOLDISPLAY) Then $sDetails &= ' and show display.'
EndIf
$aIcon[0] = @AutoItExe
$aIcon[1] = $FUNCTIONS_TABLE[$FTBL_ROW_VOLUME][$FTBL_COL_ICO]
Case Else
$aIcon[0] = @AutoItExe
For $forFunc = 0 To $FTBL_ROW_UBOUND-1
If $sFunction = $FUNCTIONS_TABLE[$forFunc][$FTBL_COL_ID] Then
$aIcon[1] = $FUNCTIONS_TABLE[$forFunc][$FTBL_COL_ICO]
ExitLoop
EndIf
Next
EndSwitch
Local $sPrompt = ''
If _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_PROMPT) Then
$sPrompt = '¹'
EndIf
Local $sVirtKey = ''
If _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_VIRTKEY) Then
$sVirtKey = '²'
EndIf
Local $sComment = _MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_COMMENT)
$sComment &= ($sComment And $sDetails) ? ' --- ' : ''
Local $lvi_Entry = GUICtrlCreateListViewItem( _
($bDisabled ? ' Disabled; ':'') & _HotKeyToString($MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY]) & $sPrompt & $sVirtKey & @CR & _
_FuncLookup($sFunction) & (_MasterKeyDataRead($MASTER_KEY_LIST[0][0], $INI_KEY_RUNADMIN) ? ' (as Admin)' : '' ) & @CR & _
$sComment & $sDetails, $lv_KeyList)
GUICtrlSetImage(-1, $aIcon[0], $aIcon[1])
If $bDisabled Then GUICtrlSetColor(-1, 0xff0000)
If $lvi_Entry >= UBound($KEY_LIST_REVLOOKUP) Then ReDim $KEY_LIST_REVLOOKUP[$lvi_Entry * 2]
$KEY_LIST_REVLOOKUP[$lvi_Entry] = $MASTER_KEY_LIST[0][0]
$MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_CTRLID] = $lvi_Entry
Next
_GUICtrlListView_SetColumnWidth($lv_KeyList, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($lv_KeyList, 1, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($lv_KeyList, 2, $LVSCW_AUTOSIZE)
EndIf
If $g_iTrayTip = 1 And $bErrorNotice Then
TraySetState()
TrayTip('Notice', 'One or more hotkeys are not functioning properly. Check key list for more detail.', 3, 3)
AdlibRegister('_HideTray', 5000)
EndIf
_TraySetTip()
_GUICtrlListView_EndUpdate($lv_KeyList)
EndFunc
#cs
Example usage:
$sHotKey = _MasterKeyDataRead($iKeyID)
$sFunction = _MasterKeyDataRead($sHotKey, $INI_KEY_FUNC)
$iKeyID = @extended
#ce
Func _MasterKeyDataRead($iKeyID, $sName = Default, $LL = @ScriptLineNumber)
If Not IsArray($MASTER_KEY_LIST) Then Return SetError(-1, -1, '')
; Lookup function for reading data in the keylist by value name
If IsString($iKeyID) Then
; If the given key ID was a string then lookup it's index number
For $for = 1 To $MASTER_KEY_LIST[0][0]
If $iKeyID = $MASTER_KEY_LIST[$for][$MKL_HOTKEY] Then
$iKeyID = $for
ExitLoop
EndIf
Next
; If the key string was not found:
If IsString($iKeyID) Then Return SetError(1, -1, '')
EndIf
If $iKeyID < 1 Or $iKeyID > $MASTER_KEY_LIST[0][0] Then
; The key lookup was invalid
Return SetError(2, $iKeyID, '')
Else
; Return the hotkey string
If $sName = Default Then Return SetExtended($iKeyID, $MASTER_KEY_LIST[$iKeyID][$MKL_HOTKEY])
Local $aKeyData = $MASTER_KEY_LIST[$iKeyID][$MKL_DATA]
; For grabbing the raw array - might remove this after debugging
If $sName = '*' Then Return SetExtended($iKeyID, $aKeyData)
For $for = 1 To $aKeyData[0][0]
If $sName = $aKeyData[$for][0] Then
Return SetExtended($iKeyID, $aKeyData[$for][1])
EndIf
Next
; The named value was not found in the key data
Return SetError(3, $iKeyID, '')
EndIf
EndFunc
Func _MasterKeyVirtKeyFunc($iVirtKey)
__HK_KeyUp($iVirtKey)
#cs
https://www.autoitscript.com/forum/topic/90492-hotkey-udf/?do=findComment&comment=1337982
If another window is granted focus immediately, then the script will not recognize that the
key has been released and will block all other keys from being typed.
This seems to be because __HK_KeyUp() is not being called properly. I assume because it
should be called on the WM_KEYUP or WM_SYSKEYUP message, and the monitoring window is not
receiving that message because a different window is active when the key is released. I
tried looking through the code to figure out where I could maybe force a check but I'm
very lost.
#ce
_MasterKeyDataRead(_VirtKeyToHotKey($iVirtKey))
Local $iKeyID = @extended
If Not @error Then
Sleep(100)
_MasterKeyExecutor($iKeyID)
_HotKey_Assign(_HotKeyToVirtKey($MASTER_KEY_LIST[$MASTER_KEY_LIST[0][0]][$MKL_HOTKEY]), '_MasterKeyVirtKeyFunc', $HK_FLAG_EXTENDEDCALL)
Else
MsgBox(0x2010, $APP_NAME, 'Invalid key data format. (' & $iVirtKey & ':' & _VirtKeyToHotKey($iVirtKey) & ')')
_ErrorLog('Invalid key data format. (' & $iVirtKey & ':' & _VirtKeyToHotKey($iVirtKey) & ')')
EndIf
EndFunc
Func _MasterKeyHotKeyFunc()
Local $sHotKey = @HotKeyPressed
_MasterKeyDataRead($sHotKey)
Local $iKeyID = @extended
If Not @error Then
HotKeySet($sHotKey)
_MasterKeyExecutor($iKeyID)
HotKeySet($sHotKey, '_MasterKeyHotKeyFunc')
Else
MsgBox(0x2010, $APP_NAME, 'Invalid key data format. (' & @HotKeyPressed & ')')
_ErrorLog('Invalid key data format. (' & @HotKeyPressed & ')')
EndIf
EndFunc
Func _MasterKeyExecutor($iKeyID)
If Not _PromptFirst($iKeyID) Then Return
Local $bPrompted = @extended
Local $sCommandFunction = _MasterKeyDataRead($iKeyID, $INI_KEY_FUNC)
Switch $sCommandFunction
#region - FireKey functions
Case $FUNCTIONS_TABLE[$FTBL_ROW_EXITHANDLER][$FTBL_COL_ID]
Exit @ScriptLineNumber
Case $FUNCTIONS_TABLE[$FTBL_ROW_OPENLIST][$FTBL_COL_ID]
_OpenKeyList()
Case $FUNCTIONS_TABLE[$FTBL_ROW_TOGGLELIST][$FTBL_COL_ID]
If WinActive($g_hGUIMain) Then
GUISetState(@SW_HIDE, $g_hGUIMain)
Else
_OpenKeyList()
EndIf
Case $FUNCTIONS_TABLE[$FTBL_ROW_CLOSELIST][$FTBL_COL_ID]
GUISetState(@SW_HIDE, $g_hGUIMain)
Case $FUNCTIONS_TABLE[$FTBL_ROW_RELOADKEYS][$FTBL_COL_ID]
_MasterKeyLoadList()
#endregion
#region - Window functions
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINCLOSE][$FTBL_COL_ID]
WinClose('[active]')
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINMIN][$FTBL_COL_ID]
WinSetState('[active]', '', @SW_MINIMIZE)
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINMAX][$FTBL_COL_ID]
WinSetState('[active]', '', @SW_MAXIMIZE)
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINRESTORE][$FTBL_COL_ID]
WinSetState('[active]', '', @SW_RESTORE)
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINMINALL][$FTBL_COL_ID]
WinMinimizeAll()
Case $FUNCTIONS_TABLE[$FTBL_ROW_WINMINALLUNDO][$FTBL_COL_ID]
WinMinimizeAllUndo()
Case $FUNCTIONS_TABLE[$FTBL_ROW_TOGGLEICONS][$FTBL_COL_ID]
Local $hDesktop = ControlGetHandle('[CLASS:Progman]', '', 'SysListView321')
If Not $hDesktop Then
Local $aWorkerW = WinList('[CLASS:WorkerW]')
For $i = 1 to $aWorkerW[0][0]
If ControlGetHandle($aWorkerW[$i][1], '', 'SHELLDLL_DefView1') Then
$hDesktop = ControlGetHandle($aWorkerW[$i][1], '', 'SysListView321')
If $hDesktop Then ExitLoop
EndIf
Next
EndIf
If $hDesktop Then
If BitAND(WinGetState($hDesktop), 2) Then
WinSetState($hDesktop, '', @SW_HIDE)
Else
WinSetState($hDesktop, '', @SW_SHOW)
EndIf
Else
MsgBox(0x2010, $APP_NAME, 'Cannot find desktop control.')
EndIf
#endregion
#region - Power functions
Case $FUNCTIONS_TABLE[$FTBL_ROW_MONOFF][$FTBL_COL_ID]
Local $WM_SYSCOMMAND = 274
Local $SC_MONITORPOWER = 61808
Local $hWnd = WinGetHandle('[CLASS:Progman]')
Sleep(500)
_SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MONITORPOWER, 2)
Case $FUNCTIONS_TABLE[$FTBL_ROW_LOGOFF][$FTBL_COL_ID]
Shutdown(0)
Case $FUNCTIONS_TABLE[$FTBL_ROW_SHUTDOWN][$FTBL_COL_ID]
Shutdown(9)
Case $FUNCTIONS_TABLE[$FTBL_ROW_REBOOT][$FTBL_COL_ID]
Shutdown(2)
Case $FUNCTIONS_TABLE[$FTBL_ROW_SLEEP][$FTBL_COL_ID]
Shutdown(32)
Case $FUNCTIONS_TABLE[$FTBL_ROW_HIBERNATE][$FTBL_COL_ID]
Shutdown(64)
#endregion
#region - Volume functions
Case $FUNCTIONS_TABLE[$FTBL_ROW_VOLUME][$FTBL_COL_ID]
Local $iAdjAmount = _MasterKeyDataRead($iKeyID, $INI_KEY_VOLADJUST)
If $iAdjAmount = $INI_KEY_MUTE Then
_ToggleMute()
Else
_AdjustVolume(Int($iAdjAmount), _MasterKeyDataRead($iKeyID, $INI_KEY_VOLDISPLAY))
EndIf
#endregion
; Run file function
Case $FUNCTIONS_TABLE[$FTBL_ROW_RUN][$FTBL_COL_ID]
Local $sPath = _MasterKeyDataRead($iKeyID, $INI_KEY_PATH)
Local $sParams = _MasterKeyDataRead($iKeyID, $INI_KEY_PARAMS)
Local $sWorkDir = _MasterKeyDataRead($iKeyID, $INI_KEY_WORKDIR)
Local $iWinStyle = Abs(Int(_MasterKeyDataRead($iKeyID, $INI_KEY_WINSTYLE)))
If $iWinStyle >= UBound($FK_WINSTYLES) Then $iWinStyle = 0
_ShellExecute($sPath, $sParams, $sWorkDir, $FK_WINSTYLES[$iWinStyle], _MasterKeyDataRead($iKeyID, $INI_KEY_RUNADMIN))
; AutoIt script file function
Case $FUNCTIONS_TABLE[$FTBL_ROW_AUTOIT][$FTBL_COL_ID]
Local $sPath = _MasterKeyDataRead($iKeyID, $INI_KEY_PATH)
Local $sParams = _MasterKeyDataRead($iKeyID, $INI_KEY_PARAMS)
_ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & $sPath & '" ' & $sParams)
; AutoIt script line function
Case $FUNCTIONS_TABLE[$FTBL_ROW_AUTOITLINE][$FTBL_COL_ID]
Local $sParams = _MasterKeyDataRead($iKeyID, $INI_KEY_PARAMS)
$sParams = StringRegExpReplace($sParams, '(\\r|\\n)', '')
$sParams = StringFormat($sParams)
$sParams = StringReplace($sParams, '"', '""')
_ShellExecute(@AutoItExe, '/AutoIt3ExecuteLine "' & $sParams & '"')
EndSwitch
EndFunc
#endregion
#region - Helper functions
Func _OpenKeyList()
GUISetState(@SW_SHOW, $g_hGUIMain)
If UBound($g_aLaunchSize) = 4 Then
If $g_aLaunchSize[0] + $g_aLaunchSize[2] < 0 Then $g_aLaunchSize[0] = 100
If $g_aLaunchSize[0] > @DesktopWidth Then $g_aLaunchSize[0] = @DesktopWidth - 100
If $g_aLaunchSize[1] < -10 Then $g_aLaunchSize[1] = 0
If $g_aLaunchSize[1] > @DesktopHeight Then $g_aLaunchSize[1] = @DesktopHeight - $g_aLaunchSize[3]/2
WinMove($g_hGUIMain, '', $g_aLaunchSize[0], $g_aLaunchSize[1], $g_aLaunchSize[2], $g_aLaunchSize[3])
$g_aLaunchSize = Null
EndIf
WinActivate($g_hGUIMain)
EndFunc
Func _ShellExecute($sPath, $sParam = '', $sWorkDir = '', $iShowFlag = @SW_SHOW, $bAsAdmin = False)
ProcessSetPriority(@AutoItPID, $PROCESS_NORMAL)
If Not ShellExecute($sPath, $sParam, $sWorkDir, $bAsAdmin ? 'RunAs' : '', $iShowFlag) Then
_ErrorLog(StringFormat('ShellExecute failed:\r\n\tPath: %s\r\n\tParams: %s\r\n\tWorkDir: %s\r\n\tAdmin: %s', $sPath, $sParam, $sWorkDir, $bAsAdmin ? 'Yes' : 'No'))
EndIf
ProcessSetPriority(@AutoItPID, $g_iPriority)
EndFunc
Func _PromptFirst($iKeyID)
If _MasterKeyDataRead($iKeyID, $INI_KEY_PROMPT) Then
Local $sPromptText = 'Continue with command?' & @LF
Local $sHint = _FuncLookup(_MasterKeyDataRead($iKeyID, $INI_KEY_FUNC))
If $sHint = $FUNCTIONS_TABLE[$FTBL_ROW_RUN][$FTBL_COL_STR] Then
$sHint &= ' ' & _MasterKeyDataRead($iKeyID, $INI_KEY_PATH)
EndIf
If MsgBox(0x42124, $APP_NAME, $sPromptText & ' > ' & $sHint, 0, $g_hGUIMain) = 6 Then
Return SetExtended(1, True)
Else
Return False
EndIf
EndIf
Return True
EndFunc
Func _AdjustVolume($iAdjAmount, $bDisplay)
Local $iSetVolume
If $USE_VISTA_FUNCS Then
$iSetVolume = Round(_GetMasterVolumeLevelScalar()) + $iAdjAmount
If $iSetVolume > 100 Then $iSetVolume = 100
If $iSetVolume < 0 Then $iSetVolume = 0
_SetMasterVolumeLevelScalar($iSetVolume)
Else
$iSetVolume = _SoundGetMasterVolume() + $iAdjAmount
If $iSetVolume > 100 Then $iSetVolume = 100
If $iSetVolume < 0 Then $iSetVolume = 0
_SoundSetMasterVolume($iSetVolume)
EndIf
If $bDisplay Then
AdlibRegister('_HideVolumeDisplay', 750)
Local $iMaxWidth = @DesktopWidth - 80
Local $iMaxHeight = @DesktopHeight / 10
Local $iWidth = Round($iMaxWidth*(($iSetVolume+1)/101))
WinMove($VOLUME_HWND, '', 40, @DesktopHeight - $iMaxHeight - 40, $iWidth, $iMaxHeight)
GUISetState(@SW_SHOWNA, $VOLUME_HWND)
WinSetOnTop($VOLUME_HWND, '', 1)
EndIf
EndFunc
Func _ToggleMute()
If $USE_VISTA_FUNCS Then
If _GetMute() Then
_SetMute(0)
Else
_SetMute(1)
EndIf
Else
If _SoundGetMasterMute() Then
_SoundSetMasterMute(0)
Else
_SoundSetMasterMute(1)
EndIf
EndIf
EndFunc
Func _HideVolumeDisplay()
AdlibUnRegister('_HideVolumeDisplay')
GUISetState(@SW_HIDE, $VOLUME_HWND)
EndFunc
Func _HideTray()
AdlibUnRegister('_HideTray')
If $g_iTrayIcon = 0 Then
TraySetState(2)
EndIf
EndFunc
Func _TraySetTip()
If IsArray($MASTER_KEY_LIST) Then
TraySetToolTip($APP_NAME & ' - ' & $MASTER_KEY_LIST[0][0] & ' hotkeys set')
Else
TraySetToolTip($APP_NAME & ' - No hotkeys set')
EndIf
EndFunc
Func _ErrorLog($sErrorMsg)
Local $hErrorLog = FileOpen($ERROR_LOG, 1)
If $hErrorLog <> -1 Then
$sErrorMsg = StringFormat('[%02d-%02d-%02d %02d:%02d:%02d] %s', @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC, $sErrorMsg)
FileWriteLine($hErrorLog, $sErrorMsg)
FileClose($hErrorLog)
EndIf
EndFunc
Func _ExitPrompt()
If $g_iConfExit = 1 And MsgBox(0x2124, $APP_NAME, 'Are you sure you want to shutdown ' & $APP_NAME & '?' & @LF & 'This will disable all hotkeys.', 0, $g_hGUIMain) <> 6 Then Return
Exit @ScriptLineNumber
EndFunc
Func _ToolTipClear()
AdlibUnRegister('_ToolTipClear')
ToolTip('')
EndFunc
Func _StringEscape($sString)
$sString = StringReplace($sString, '%', '%%')
$sString = StringReplace($sString, '\', '\\')
$sString = StringReplace($sString, @CR, '')
$sString = StringReplace($sString, @LF, '\n')
$sString = StringReplace($sString, @TAB, '\t')
Return $sString
EndFunc
#endregion
#region - GUI functions
Func _MainHandler()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
If $g_iTrayIcon Then
GUISetState(@SW_HIDE, $g_hGUIMain)
Else
_ExitPrompt()
EndIf