-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathSendGUI.ahk
1110 lines (980 loc) · 29.6 KB
/
SendGUI.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
SendGUI()
;-----------------------------
;
; Function: SendGUI
;
; Description:
;
; This function displays a dialog that will allow the user to select a hotkey
; without using the keyboard. See the "Processing and Usage Notes" section
; for more information.
;
;
; Parameters:
;
; p_Owner - The GUI owner of the SendGUI window. [Optional] The default is
; 0 (no owner). If not defined, the AlwaysOnTop attribute is added to the
; SendGUI window to make sure that the window is not lost.
;
; p_Hotkey - The default hotkey value. [Optional] The default is blank. To
; only preselect modifiers and/or optional attributes, enter only the
; associated characters. For example, to only have the Ctrl and Shift
; modifiers set as the default, enter "^+".
;
; p_Limit - Hotkey limit. [Optional] The default is 0. See the "Hotkey
; Limits" section below for more information.
;
; p_OptionalAttrib - Optional hotkey attributes. [Optional] The default is
; FALSE. If set to TRUE, all items in the Optional Attributes group are
; enabled and the user is allowed to add or remove optional attributes.
;
; p_Title - Window title. [Optional] The default is the current script name
; (sans the extention) plus "Select Hotkey".
;
;
; Processing And Usage Notes:
;
; Stuff to know...
;
; * The function does not return until the SendGUI window is closed
; (Accept or Cancel).
;
; * A shift-only key (Ex: ~!@#$%^&*()_+{}|:"<>?) cannot be directly selected
; as a key by this function. To use a shift-only key, select the Shift
; modifier and then select the non-shift version of the key. For example,
; to set the "(" key as a hotkey, select the Shift modifier and then
; select the "9" key. The net result is the "(" key. In addition,
; shift-only keys are not supported as values for the p_Hotkey parameter
; as a default hotkey. If a shift-only key is used, no default key will
; be selected.
;
; * To resolve a minor AutoHotkey inconsistency, the "Pause" key and the
; "Break" keys are automatically converted to the "CtrlBreak" key if the
; Ctrl modifier is selected. The "CtrlBreak" key is automatically
; converted to the "Pause" key if the Ctrl modifier is not selected.
;
;
; Hotkey Limits:
;
; The p_Limit parameter allows the developer to restrict the types of keys
; that are selected. The following limit values are available:
;
; (start code)
; Limit Description
; ----- -----------
; 1 Prevent unmodified keys
; 2 Prevent Shift-only keys
; 4 Prevent Ctrl-only keys
; 8 Prevent Alt-only keys
; 16 Prevent Win-only keys
; 32 Prevent Shift-Ctrl keys
; 64 Prevent Shift-Alt keys
; 128 Prevent Shift-Win keys
; 256 Prevent Shift-Ctrl-Alt keys
; 512 Prevent Shift-Ctrl-Win keys
; 1024 Prevent Shift-Win-Alt keys
; (end)
;
; To use a limit, enter the sum of one or more of these limit values. For
; example, a limit value of 1 will prevent unmodified keys from being used.
; A limit value of 31 (1 + 2 + 4 + 8 + 16) will require that at least two
; modifier keys be used.
;
;
; Returns:
;
; If the function ends after the user has selected a valid key and the
; "Accept" button is pressed, the function returns the selected key in the
; standard AutoHotkey hotkey format and ErrorLevel is set to 0.
; Example: Hotkey=^a ErrorLevel=0
;
; If the SendGUI window is canceled (Cancel button, Close button, or Escape
; key), the function returns the original hotkey value (p_Hotkey) and
; Errorlevel is set to 1.
;
; If the function is unable to create a SendGUI window for any reason,
; ErrorLevel is set to the word FAIL.
;
;
; Calls To Other Functions:
;
; PopupXY (optional)
;
;
; Hotkey Support:
;
; AutoHotkey is a very robust program and can accept hotkey definitions in an
; multitude of formats. Unfortunately, this function is not that robust and
; there are a couple of important limitations:
;
; 1. The p_Limit parameter restricts the type of keys that can be supported.
; For this reason, the following keys are not supported:
;
; * *Modifier keys* (as hotkeys). Example: Alt, Shift, LWin, etc.
; * *Joystick keys*. Example: Joy1, Joy2, etc.
; * *Custom combinations*. Example: Numpad0 & Numpad1.
;
; 2. Shift-only keys (Ex: "~","!","@","#",etc.) are not supported. See the
; "Processing and Usage Notes" section for more information.
;
;
; Programming Notes:
;
; To keep the code as friendly as possible, static variables (in lieu of
; global variables) are used whenever a GUI object needs a variable. Object
; variables are defined so that a single "gui Submit" command can be used to
; collect the GUI values instead of having to execute a "GUIControlGet"
; command on every GUI control. For the few GUI objects that are
; programmatically updated, the ClassNN (class name and instance number of the
; object Ex: Static4) is used.
;
; Important: Any changes to the GUI (additions, deletions, etc.) may change
; the ClassNN of objects that are updated. Use Window Spy (or similar
; program) to identify any changes.
;
;-------------------------------------------------------------------------------
SendGUI(p_Owner=0,p_Hotkey="",p_Limit="",p_OptionalAttrib=False,p_Title="")
{
; Gui, Options:+Disabled
;[====================]
;[ Static variables ]
;[====================]
Static s_GUI:=0
;-- This variable stores the currently active GUI. If not zero
; when entering the function, the GUI is currently showing.
,s_StartGUI:=53
;-- Default starting GUI window number for SendGUI window.
; Change if desired.
,s_PopupXY_Function:="PopupXY"
;-- Name of the PopupXY function. Defined as a variable so that
; function will use if the "PopupXY" function is included but
; will not fail if it's not.
;[===========================]
;[ Window already showing? ]
;[===========================]
if s_GUI
{
Errorlevel:="FAIL"
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc% -
A %A_ThisFunc% window already exists. Errorlevel=FAIL
)
Return
}
;[==============]
;[ Initialize ]
;[==============]
SplitPath A_ScriptName,,,,l_ScriptName
l_ErrorLevel :=0
;-------------
;-- Key lists
;-------------
;-- Standard keys
l_StandardKeysList=
(ltrim join|
a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
0|1|2|3|4|5|6|7|8|9|0
{``}|{-}|{=}|{[}|{]}|{`\}|{+}|;
'|,|.|/
{Space}
{Tab}
{Enter}
{Escape}
{Backspace}
{Delete}
{ScrollLock}
{CapsLock}
{NumLock}
{PrintScreen}
{CtrlBreak}
{Pause}
{Break}
{Insert}
{Home}
{End}
{PgUp}
{PgDn}
{Up}
{Down}
{Left}
{Right}
)
;-- Function keys
l_FunctionKeysList=
(ltrim join|
{F1}|{F2}|{F3}|{F4}|{F5}|{F6}|{F7}|{F8}|{F9}|{F10}
{F11}|{F12}|{F13}|{F14}|{F15}|{F16}|{F17}|{F18}|{F19}|{F20}
{F21}|{F22}|{F23}|{F24}
)
;-- Numpad
l_NumpadKeysList=
(ltrim join|
{NumLock}
{NumpadDiv}
{NumpadMult}
{NumpadAdd}
{NumpadSub}
{NumpadEnter}
{NumpadDel}
{NumpadIns}
{NumpadClear}
{NumpadUp}
{NumpadDown}
{NumpadLeft}
{NumpadRight}
{NumpadHome}
{NumpadEnd}
{NumpadPgUp}
{NumpadPgDn}
{Numpad0}
{Numpad1}
{Numpad2}
{Numpad3}
{Numpad4}
{Numpad5}
{Numpad6}
{Numpad7}
{Numpad8}
{Numpad9}
{NumpadDot}
)
;-- Mouse
l_MouseKeysList=
(ltrim join|
{LButton}
{RButton}
{MButton}
{WheelDown}
{WheelUp}
{XButton1}
{XButton2}
)
;-- Multimedia
l_MultimediaKeysList=
(ltrim join|
{Browser_Back}
{Browser_Forward}
{Browser_Refresh}
{Browser_Stop}
{Browser_Search}
{Browser_Favorites}
{Browser_Home}
{Volume_Mute}
{Volume_Down}
{Volume_Up}
{Media_Next}
{Media_Prev}
{Media_Stop}
{Media_Play_Pause}
{Launch_Mail}
{Launch_Media}
{Launch_App1}
{Launch_App2}
)
;-- Special
l_SpecialKeysList:="{Help}|{Sleep}|{AppsKey}"
;[==================]
;[ Parameters ]
;[ (Set defaults) ]
;[==================]
;-- Owner
; p_Owner=%p_Owner% ;-- AutoTrim
; if p_Owner is not Integer
; p_Owner:=0
; else
; if p_Owner not Between 1 and 99
; p_Owner:=0
;-- Owner window exists?
if p_Owner
{
gui %p_Owner%:+LastFoundExist
IfWinNotExist
{
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% -
Owner window does not exist. p_Owner=%p_Owner%
)
p_Owner:=0
}
}
;-- Default hotkey
l_Hotkey=%p_Hotkey% ;-- AutoTrim
;-- Limit
p_Limit=%p_Limit% ;-- AutoTrim
if p_Limit is not Integer
p_Limit:=0
else
if p_Limit not between 0 and 2047
p_Limit:=0
;-- Title
p_Title=%p_Title% ;-- AutoTrim
if p_Title is Space
p_Title:=l_ScriptName . " - Select Hotkey"
else
{
;-- Append to script name if p_title begins with "++"?
if SubStr(p_Title,1,2)="++"
{
StringTrimLeft p_Title,p_Title,2
p_Title:=l_ScriptName . A_Space . p_Title
}
}
;[==============================]
;[ Find available window ]
;[ (Starting with s_StartGUI) ]
;[==============================]
s_GUI:=s_StartGUI
Loop
{
;-- Window available?
gui %s_GUI%:+LastFoundExist
IfWinNotExist
Break
;-- Nothing available?
if (s_GUI=99)
{
MsgBox
,262160
;-- 262160=0 (OK button) + 16 (Error icon) + 262144 (AOT)
,%A_ThisFunc% Error,
(ltrim join`s
Unable to create a %A_ThisFunc% window. GUI windows
%s_StartGUI% to 99 are already in use. %A_Space%
)
s_GUI:=0
ErrorLevel:="FAIL"
Return
}
;-- Increment window
s_GUI++
}
;[=============]
;[ Build GUI ]
;[=============]
;-- Assign ownership
if p_Owner
{
gui %p_Owner%:+Disabled ;-- Disable Owner window
gui %s_GUI%:+Owner%p_Owner% ;-- Set ownership
}
else
gui %s_GUI%:+Owner ;-- Gives ownership to the script window
;-- GUI options
gui %s_GUI%:Margin,6,6
gui %s_GUI%:-MinimizeBox +LabelSendGUI_
if not p_Owner
gui %s_GUI%:+AlwaysOnTop
;---------------
;-- GUI objects
;---------------
;-- Modifiers
Static HG_ModifierGB
gui %s_GUI%:Add
,GroupBox
, xm y10 w170 h10 vHG_ModifierGB
,Modifier
Static HG_CtrlModifier
gui %s_GUI%:Add
,CheckBox
,xp+10 yp+20 Section vHG_CtrlModifier gSendGUI_UpdateHotkey
,Ctrl
Static HG_ShiftModifier
gui %s_GUI%:Add
,CheckBox
,xs vHG_ShiftModifier gSendGUI_UpdateHotkey
,Shift
Static HG_WinModifier
gui %s_GUI%:Add
,CheckBox
,xs vHG_WinModifier gSendGUI_UpdateHotkey Disabled
,Win
Static HG_AltModifier
gui %s_GUI%:Add
,CheckBox
,xs vHG_AltModifier gSendGUI_UpdateHotkey
,Alt
;-- Optional Attributes
Static HG_OptionalAttributesGB
gui %s_GUI%:Add
,GroupBox
,xs+160 y10 w170 h10 vHG_OptionalAttributesGB
,Optional Attributes
Static HG_NativeOption
gui %s_GUI%:Add
,CheckBox
,xp+10 yp+20 Disabled Section vHG_NativeOption gSendGUI_UpdateHotkey
,~ (Native)
Static HG_WildcardOption
gui %s_GUI%:Add
,CheckBox
,xs Disabled vHG_WildcardOption gSendGUI_UpdateHotkey
,* (Wildcard)
Static HG_LeftPairOption
gui %s_GUI%:Add ;-- Button9
,CheckBox
,xs Disabled vHG_LeftPairOption gSendGUI_LeftPair
,< (Left pair only)
Static HG_RightPairOption
gui %s_GUI%:Add ;-- Button10
,CheckBox
,xs Disabled vHG_RightPairOption gSendGUI_RightPair
,> (Right pair only)
;-- Enable "Optional Attributes"?
if p_OptionalAttrib
{
GUIControl %s_GUI%:Enable,HG_NativeOption
GUIControl %s_GUI%:Enable,HG_WildcardOption
GUIControl %s_GUI%:Enable,HG_LeftPairOption
GUIControl %s_GUI%:Enable,HG_RightPairOption
}
;-- Resize the Modifier and Optional Attributes group boxes
GUIControlGet $Group1Pos,%s_GUI%:Pos,HG_OptionalAttributesGB
GUIControlGet $Group2Pos,%s_GUI%:Pos,HG_RightPairOption
GUIControl
,%s_GUI%:Move
,HG_ModifierGB
,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
GUIControl
,%s_GUI%:Move
,HG_OptionalAttributesGB
,% "h" . ($Group2PosY-$Group1PosY)+$Group2PosH+10
;-- Keys
YPos:=($Group2PosY-$Group1PosY)+$Group2PosH+20
gui %s_GUI%:Add
,GroupBox
,xm y%YPos% w340 h180
,Keys
Static HG_StandardKeysView
gui %s_GUI%:Add
,Radio
,xp+10 yp+20 Checked Section vHG_StandardKeysView gSendGUI_UpdateKeyList
,Standard
Static HG_FunctionKeysView
gui %s_GUI%:Add
,Radio
,xs vHG_FunctionKeysView gSendGUI_UpdateKeyList
,Function keys
Static HG_NumpadKeysView
gui %s_GUI%:Add
,Radio
,xs vHG_NumpadKeysView gSendGUI_UpdateKeyList
,Numpad
Static HG_MouseKeysView
gui %s_GUI%:Add
,Radio
,xs vHG_MouseKeysView gSendGUI_UpdateKeyList
,Mouse
Static HG_MultimediaKeysView
gui %s_GUI%:Add
,Radio
,xs vHG_MultimediaKeysView gSendGUI_UpdateKeyList
,Multimedia
Static HG_SpecialKeysView
gui %s_GUI%:Add
,Radio
,xs vHG_SpecialKeysView gSendGUI_UpdateKeyList
,Special
Static HG_Key
gui %s_GUI%:Add
,ListBox ;-- ListBox1
,xs+140 ys w180 h150 vHG_Key gSendGUI_UpdateHotkey
;-- Set initial values
gosub SendGUI_UpdateKeyList
;-- Hotkey display
YPos+=190
gui %s_GUI%:Add
,Text
,xm y%YPos% w70
,Hotkey:
gui %s_GUI%:Add
,Edit ;-- Edit1
,x+0 w270 +ReadOnly
gui %s_GUI%:Add
,Text
,xm y+5 w70 r2 hp
,Desc:
gui %s_GUI%:Add
,Text ;-- Static3
,x+0 w270 hp +ReadOnly
,None
;-- Buttons
Static HG_AcceptButton
gui %s_GUI%:Add ;-- Button18
,Button
,xm y+5 Default Disabled vHG_AcceptButton gSendGUI_AcceptButton
,%A_Space% &Accept %A_Space%
;-- Note: All characters are used to determine the button's W+H
gui %s_GUI%:Add
,Button
,x+5 wp hp gSendGUI_Close
,Cancel
Gui, %s_GUI%:Font, underline
Gui, %s_GUI%:Add, Text, x+150 cBlue gLinkLabel2, Hotkey Help ;linklabel is in the other hotkeygui (as 'link' stoppped working)
Gui, %s_GUI%:Font, norm
;[================]
;[ Set defaults ]
;[================]
if l_Hotkey is not Space
{
;-- Modifiers and optional attributes
Loop
{
l_FirstChar:=SubStr(l_Hotkey,1,1)
if l_FirstChar in ^,+,#,!,~,*,<,>
{
if (l_FirstChar="^")
GUIControl %s_GUI%:,HG_CtrlModifier,1
else if (l_FirstChar="+")
GUIControl %s_GUI%:,HG_ShiftModifier,1
else if (l_FirstChar="#")
GUIControl %s_GUI%:,HG_WinModifier,1
else if (l_FirstChar="!")
GUIControl %s_GUI%:,HG_AltModifier,1
else if (l_FirstChar="~")
GUIControl %s_GUI%:,HG_NativeOption,1
else if (l_FirstChar="*")
GUIControl %s_GUI%:,HG_WildcardOption,1
else if (l_FirstChar="<")
GUIControl %s_GUI%:,HG_LeftPairOption,1
else if (l_FirstChar=">")
GUIControl %s_GUI%:,HG_RightPairOption,1
;-- On to the next
StringTrimLeft l_Hotkey,l_Hotkey,1
Continue
}
;-- We're done here
Break
}
;-- Find key in key lists
if l_Hotkey is not Space
{
;-- Standard keys
if Instr("|" . l_StandardKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_StandardKeysView,1
;-- Function keys
else if Instr("|" . l_FunctionKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_FunctionKeysView,1
;-- Numpad keys
else if Instr("|" . l_NumpadKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_NumpadKeysView,1
;-- Mouse keys
else if Instr("|" . l_MouseKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_MouseKeysView,1
;-- Multimedia keys
else if Instr("|" . l_MultimediaKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_MultimediaKeysView,1
;-- Special keys
else if Instr("|" . l_SpecialKeysList . "|","|" . l_Hotkey . "|")
GUIControl %s_GUI%:,HG_SpecialKeysView,1
;-- Update keylist and select it
gosub SendGUI_UpdateKeyList
GUIControl %s_GUI%:ChooseString,HG_Key,%l_Hotkey%
}
;-- Update Hotkey field and description
gosub SendGUI_UpdateHotkey
}
If (p_Limit = 2046)
{
GUIControl %s_GUI%:Disable, HG_CtrlModifier
GUIControl %s_GUI%:, HG_CtrlModifier, 0
GUIControl %s_GUI%:Disable, HG_ShiftModifier
GUIControl %s_GUI%:, HG_ShiftModifier,0
GUIControl %s_GUI%:Disable, HG_WinModifier, 0
GUIControl %s_GUI%:,HG_WinModifier,0
GUIControl %s_GUI%:Disable, HG_AltModifier
GUIControl %s_GUI%:, HG_AltModifier, 0
}
;[=============]
;[ Set focus ]
;[=============]
GUIControl %s_GUI%:Focus,HG_AcceptButton
;-- Note: This only works when the Accept button is enabled
;[================]
;[ Collect hWnd ]
;[================]
gui %s_GUI%:+LastFound
WinGet l_SendGUI_hWnd,ID
;[===============]
;[ Show window ]
;[===============]
if p_Owner and IsFunc(s_PopupXY_Function)
{
gui %s_GUI%:Show,Hide,%p_Title% ;-- Render but don't show
%s_PopupXY_Function%(p_Owner,"ahk_id " . l_SendGUI_hWnd,PosX,PosY)
gui %s_GUI%:Show,x%PosX% y%PosY% ;-- Show in the correct location
}
else
gui %s_GUI%:Show,,%p_Title%
;[=====================]
;[ Loop until window ]
;[ is closed ]
;[=====================]
WinWaitClose ahk_id %l_SendGUI_hWnd%
;[====================]
;[ Return to sender ]
;[====================]
ErrorLevel:=l_ErrorLevel
Return HG_HotKey ;-- End of function
LinkLabel2:
Run http://www.autohotkey.com/docs/Hotkeys.htm
Return
;*****************************
;* *
;* *
;* Subroutines *
;* (SendGUI) *
;* *
;* *
;*****************************
;***********************
;* *
;* Update Hotkey *
;* *
;***********************
SendGUI_UpdateHotkey:
;-- Collect form values
gui %s_GUI%:Submit,NoHide
;-- Enable/Disable Accept button
if (HG_Key || HG_Key = 0)
GUIControl %s_GUI%:Enable,Button18
else
GUIControl %s_GUI%:Disable,Button18
;-- Substitute Pause|Break for CtrlBreak?
if HG_Key in Pause,Break
if HG_CtrlModifier
HG_Key:="CtrlBreak"
;-- Substitute CtrlBreak for Pause (Break would work OK too)
if (HG_Key="CtrlBreak")
if not HG_CtrlModifier
HG_Key:="Pause"
;[================]
;[ Build Hotkey ]
;[================]
;-- Initialize
HG_Hotkey:=""
HG_HKDesc:=""
;-- Options
if HG_NativeOption
HG_Hotkey.="~"
if HG_WildcardOption
HG_Hotkey.="*"
if HG_LeftPairOption
HG_Hotkey.="<"
if HG_RightPairOption
HG_Hotkey.=">"
;-- Modifiers
if HG_CtrlModifier
{
HG_Hotkey.="^"
HG_HKDesc.="Ctrl + "
}
if HG_ShiftModifier
{
HG_Hotkey.="+"
HG_HKDesc.="Shift + "
}
if HG_WinModifier
{
HG_Hotkey.="#"
HG_HKDesc.="Win + "
}
if HG_AltModifier
{
HG_Hotkey.="!"
HG_HKDesc.="Alt + "
}
HG_Hotkey.=HG_Key
HG_HKDesc.=HG_Key
;-- Update Hotkey and HKDescr fields
GUIControl %s_GUI%:,Edit1,%HG_Hotkey%
GUIControl %s_GUI%:,Static3,%HG_HKDesc%
return
;**********************
;* *
;* Pair options *
;* *
;**********************
SendGUI_LeftPair:
;-- Deselect HG_RightPairOption
GUIControl %s_GUI%:,Button10,0
gosub SendGUI_UpdateHotkey
return
SendGUI_RightPair:
;-- Deselect HG_LeftPairOption
GUIControl %s_GUI%:,Button9,0
gosub SendGUI_UpdateHotkey
return
;*************************
;* *
;* Update Key List *
;* *
;*************************
SendGUI_UpdateKeyList:
;-- Collect form values
gui %s_GUI%:Submit,NoHide
;-- Standard
if HG_StandardKeysView
l_KeysList:=l_StandardKeysList
else
;-- Function keys
if HG_FunctionKeysView
l_KeysList:=l_FunctionKeysList
else
;-- Numpad
if HG_NumpadKeysView
l_KeysList:=l_NumpadKeysList
else
;-- Mouse
if HG_MouseKeysView
l_KeysList:=l_MouseKeysList
else
;-- Multimedia
if HG_MultimediaKeysView
l_KeysList:=l_MultimediaKeysList
else
;-- Special
if HG_SpecialKeysView
l_KeysList:=l_SpecialKeysList
;-- Update l_KeysList
GUIControl %s_GUI%:-Redraw,ListBox1
GUIControl %s_GUI%:,ListBox1,|%l_KeysList%
GUIControl %s_GUI%:+Redraw,ListBox1
;--- Reset HG_Hotkey and HG_HKDesc
HG_Key:=""
gosub SendGUI_UpdateHotkey
return
;***********************
;* *
;* Accept Button *
;* *
;***********************
SendGUI_AcceptButton:
;-- (The following test is now redundant but it is retained as a fail-safe)
;-- Any key?
if HG_Key is Space
{
gui %s_GUI%:+OwnDialogs
MsgBox
,16 ;-- Error icon
,%p_Title%
,A key must be selected. %A_Space%
return
}
;[===============]
;[ Limit tests ]
;[===============]
l_Limit:=p_Limit
l_LimitFailure:=False
;-- Loop until failure or until all tests have been performed
Loop
{
;-- Are we done here?
if (l_limit<=0)
Break
;-----------------
;-- Shift+Win+Alt
;-----------------
if (l_limit>=1024)
{
if (HG_ShiftModifier and HG_WinModifier and HG_AltModifier)
{
l_Message:="SHIFT+WIN+ALT keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=1024
Continue
}
;------------------
;-- Shift+Ctrl+Win
;------------------
if (l_limit>=512)
{
if (HG_ShiftModifier and HG_CtrlModifier and HG_WinModifier)
{
l_Message:="SHIFT+CTRL+WIN keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=512
Continue
}
;------------------
;-- Shift+Ctrl+Alt
;------------------
if (l_limit>=256)
{
if (HG_ShiftModifier and HG_CtrlModifier and HG_AltModifier)
{
l_Message:="SHIFT+CTRL+ALT keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=256
Continue
}
;-------------
;-- Shift+Win
;-------------
if (l_limit>=128)
{
if (HG_ShiftModifier and HG_WinModifier)
{
l_Message:="SHIFT+WIN keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=128
Continue
}
;-------------
;-- Shift+Alt
;-------------
if (l_limit>=64)
{
if (HG_ShiftModifier and HG_AltModifier)
{
l_Message:="SHIFT+ALT keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=64
Continue
}
;--------------
;-- Shift+Ctrl
;--------------
if (l_limit>=32)
{
if (HG_ShiftModifier and HG_CtrlModifier)
{
l_Message:="SHIFT+CTRL keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=32
Continue
}
;------------
;-- Win only
;------------
if (l_limit>=16)
{
if (HG_WinModifier
and not (HG_CtrlModifier or HG_ShiftModifier or HG_AltModifier))
{
l_Message:="WIN-only keys are not allowed."
l_LimitFailure:=True
Break
}
l_limit-=16
Continue
}
;------------
;-- Alt only
;------------
if (l_limit>=8)
{
if (HG_AltModifier
and not (HG_CtrlModifier or HG_ShiftModifier or HG_WinModifier))
{
l_Message:="ALT-only keys are not allowed."
l_LimitFailure:=True
Break
}