PageRenderTime 125ms CodeModel.GetById 115ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/HotkeyGUI.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 1014 lines | 472 code | 184 blank | 358 comment | 57 complexity | 0ce2bc6982d602af7d7d661c4d000206 MD5 | raw file
   1; ************************
   2; *                      *
   3; *    HotkeyGUI v0.2    *
   4; *                      *
   5; ************************
   6;
   7;
   8;   Description
   9;   ===========
  10;   This function displays a GUI window that will allow a user to enter/select a
  11;   hotkey without using the keyboard.  See the "Processing Notes" section for
  12;   more information.
  13;
  14;
  15;
  16;   Parameters
  17;   ==========
  18;
  19;       Name                Description
  20;       -----               -----------
  21;       p_GUI               The GUI window number.  [Optional]  The default
  22;                           is 81.  Only specify a window number here if it is
  23;                           important to know the exact window number that will
  24;                           be used.  See the "Processing Notes" section (below)
  25;                           for more information.
  26;
  27;
  28;       p_ParentGUI         The GUI owner of the HotkeyGUI window.  [Optional]
  29;                           The default is 1.
  30;
  31;
  32;       p_Title             Window title.  [Optional]  The default is the
  33;                           current script name (sans the extention) plus
  34;                           " - Select Hotkey".
  35;
  36;
  37;       p_Limit             Hotkey limit.  [Optional]  The default is 0.  See
  38;                           the "Hotkey Limit" section below for more
  39;                           information.
  40;
  41;
  42;       p_LimitMsg          Hotkey Limit message.  [Optional].  The default is
  43;                           true.
  44;
  45;                           If true and a hotkey limit is reached, an error
  46;                           message is displayed and the user returned back to
  47;                           the HotkeyGUI window.
  48;
  49;                           If false and a hotkey limit is reached, the function
  50;                           returns the selected hotkey and ErrorLevel (system
  51;                           variable) is set to the Hotkey limit that was
  52;                           reached.
  53;
  54;                           See the "Hotkey Limit" section below for more
  55;                           information.
  56;
  57;
  58;       p_OptionalAttrib    Optional hotkey attributes.  [Optional].  The
  59;                           default is true.
  60;
  61;                           If true, all fields in the "Optional Attributes"
  62;                           group are enabled.  If false, all of these fields
  63;                           are disabled.
  64;
  65;    p_filter      Used for hotkey collision check, if program-specific
  66;              hotkeys are used, to allow overrides
  67;
  68;    p_exclude      Used for hotkey collision check, this key is not considered
  69;              a collision (useful when editing existing hotkey)
  70;
  71;
  72;   Processing Notes
  73;   ================
  74;    o  This function disables the parent window and assigns ownership of the
  75;       HotkeyGUI window to the parent window.  This makes the HotkeyGUI window
  76;       modal which prevents the user from interacting with the parent window
  77;       until the HotkeyGUI window is closed.  Unfortunately, it doesn't
  78;       prevent the end user from interacting with the parent window via
  79;       hotkeys, timers, etc.
  80;
  81;    o  To improve usability, this function does not exit until the user closes
  82;       the the HotkeyGUI window.  If a hotkey is used to trigger a call to this
  83;       function, that same hotkey cannot be triggered again (if using the
  84;       system default of #MaxThreadsPerHotkey 1) until the HotkeyGUI window is
  85;       closed.
  86;
  87;   o   This function uses the first GUI window that is available in the p_GUI
  88;       (usually 81) to 99 range. If an available window cannot be found, an
  89;       error message is displayed.
  90;
  91;       Important:  Although this function can theoretically create up to 99
  92;       independent windows, creating more than one HotkeyGUI window at a time
  93;       is not recommended because the parent GUI window is automatically
  94;       re-enabled when a HotkeyGUI window is closed.  When this occurs, any
  95;       HotkeyGUI window still open becomes modeless (non-modal).
  96;
  97;
  98;
  99;   Hotkey Limits
 100;   =============
 101;   The p_Limit parameter allows the developer to restrict the types of keys
 102;   that are selected.  The following limit values are available:
 103;
 104;       Limit   Description
 105;       -----   -----------
 106;       1       Prevent unmodified keys
 107;       2       Prevent Shift-only keys
 108;       4       Prevent Ctrl-only keys
 109;       8       Prevent Alt-only keys
 110;       16      Prevent Win-only keys
 111;       32      Prevent Shift-Ctrl keys
 112;       64      Prevent Shift-Alt keys
 113;       128     Prevent Shift-Win keys
 114;       256     Prevent Shift-Ctrl-Alt keys
 115;       512     Prevent Shift-Ctrl-Win keys
 116;       1024    Prevent Shift-Win-Alt keys
 117;
 118;   To use a limit, enter the sum of one or more of these limit values.  For
 119;   example, a limit value of 1 will prevent unmodified keys from being used.
 120;   A limit value of 31 (1 + 2 + 4 + 8 + 16) will require that at least two
 121;   modifier keys be used.
 122;
 123;
 124;
 125;   Return Codes
 126;   ============
 127;   If the function ends after the user has selected a valid key and the
 128;   "Accept" button is clicked, the function returns the selected key in the
 129;   standard AHK hotkey format and ErrorLevel is set to 0.
 130;   Example: Hotkey=^a  ErrorLevel=0
 131;
 132;   If p_LimitMsg is false and a key limit test has failed, the function will
 133;   return the selected hotkey and ErrorLevel is set to the limit value that
 134;   failed.  Example: Hotkey=^a  ErrorLevel=4
 135;
 136;   If the HotkeyGUI window is canceled (Cancel button, Close button, or Escape
 137;   key), the function returns a null value and Errorlevel is set to 10003.
 138;
 139;
 140;   Important: ErrorLevel is a system variable and is used by many commands.
 141;   If you are unable to test ErrorLevel immediate after calling this function,
 142;   assign the value to another variable so that the return value is retained.
 143;
 144;
 145;
 146;   Calls To Other Functions
 147;   ========================
 148;   DisplayMessage
 149;   EMessage
 150;
 151;
 152;
 153;   Programming Notes
 154;   =================
 155;   No global variables are used.  However, to get around the use of global
 156;   variables (especially when creating a GUI inside of a function), several
 157;   changes were made:
 158;
 159;    -  To keep the code as friendly as possible, static variables (in lieu of
 160;       global variables) are used whenever a GUI object needs a variable.
 161;       Object variables are defined so that a single "gui Submit" command can
 162;       be used to collect the GUI values instead of having to execute a
 163;       "GUIControlGet" command on every GUI control.
 164;
 165;   -   For the few GUI objects that are programmatically updated, the ClassNN
 166;       (class name and instance number of the object  Ex: Static4) is used.
 167;
 168;   Important: Any changes to the GUI (additions, deletions, etc.) may change
 169;   the ClassNN of objects that are updated.  Use Window Spy (or similar
 170;   program) to identify any changes.
 171;
 172;
 173;-------------------------------------------------------------------------------
 174HotkeyGUI(p_GUI=""
 175    ,p_ParentGUI=""
 176    ,p_Title=""
 177    ,p_Limit=""
 178    ,p_LimitMsg=""
 179    ,p_OptionalAttrib=""
 180 ,p_filter=""
 181  ,p_exclude="")
 182    {
 183  Critical, Off
 184    ;[==============]
 185    ;[  Initialize  ]
 186    ;[==============]
 187    SplitPath A_ScriptName,,,,l_ScriptName
 188    l_GUIDelimiter:="ƒ"
 189    l_ErrorLevel=0
 190
 191
 192    ;[==================]
 193    ;[    Parameters    ]
 194    ;[  (Set defaults)  ]
 195    ;[==================]
 196    ;-- GUI
 197    p_GUI=%p_GUI%  ;-- AutoTrim
 198    if p_GUI is not Integer
 199        p_GUI=81
 200     else
 201        if p_GUI not between 1 and 99
 202            p_GUI=81
 203
 204
 205    ;-- Parent GUI
 206    p_ParentGUI=%p_ParentGUI%  ;-- AutoTrim
 207    if p_ParentGUI is not Integer
 208        p_ParentGUI=1
 209     else
 210        if p_ParentGUI not between 1 and 99
 211            p_ParentGUI=1
 212
 213
 214    ;-- Title
 215    p_Title=%p_Title%  ;-- AutoTrim
 216    if strlen(p_Title)=0
 217        p_Title:=l_ScriptName . " - Select Hotkey"
 218     else
 219        {
 220        ;-- Append to script name if p_title begins with "++"?
 221        if instr(p_Title,"++")=1
 222            {
 223            StringTrimLeft p_Title,p_Title,2
 224            p_Title:=l_ScriptName . A_Space . p_Title
 225            }
 226        }
 227
 228
 229    ;-- Limit
 230    p_Limit=%p_Limit%  ;-- AutoTrim
 231    if p_Limit is not Integer
 232        p_Limit=0
 233     else
 234        if p_Limit not between 0 and 2047
 235            p_Limit=0
 236
 237
 238    ;-- LimitMsg
 239    p_LimitMsg=%p_LimitMsg%  ;-- AutoTrim
 240    if p_LimitMsg is not Integer
 241        p_LimitMsg:=true
 242     else
 243        if p_LimitMsg not between 0 and 1
 244            p_LimitMsg:=true
 245
 246
 247    ;-- OptionalAttrib
 248    p_OptionalAttrib=%p_OptionalAttrib%  ;-- AutoTrim
 249    if p_OptionalAttrib is not Integer
 250        p_OptionalAttrib:=true
 251     else
 252        if p_OptionalAttrib not between 0 and 1
 253            p_OptionalAttrib:=true
 254
 255  HG_Filter := p_filter
 256  HG_Exclude := p_exclude
 257    ;[=========================]
 258    ;[  Find available window  ]
 259    ;[  (Starting with p_GUI)  ]
 260    ;[=========================]
 261    l_GUI:=p_GUI
 262    loop
 263        {
 264        ;-- Window available?
 265        gui %l_GUI%:+LastFoundExist
 266        IfWinNotExist
 267            break
 268
 269        ;-- Nothing available?
 270        if l_GUI=99
 271            {
 272            MsgBox 262160
 273                ,HotkeyGUI Error
 274                ,Unable to create HotkeyGUI window. GUI windows %p_GUI% to 99 are already in use.
 275            ErrorLevel=9999
 276            return ""
 277            }
 278
 279        ;-- Increment window
 280        l_GUI++
 281        }
 282
 283    ;[===================]
 284    ;[  Set GUI default  ]
 285    ;[===================]
 286    gui %l_GUI%:Default
 287
 288
 289    ;[=====================]
 290    ;[  Build/Display GUI  ]
 291    ;[=====================]
 292    ;-- Disable parent GUI
 293    gui %p_ParentGUI%:+Disabled
 294
 295    ;-- Set ownership
 296    gui +Owner%p_ParentGUI%
 297
 298    ;-- Set margins
 299    gui Margin,6,6
 300
 301    ;-- GUI options
 302    gui -MinimizeBox +LabelHotkeyGUI +Delimiter%l_GUIDelimiter%
 303
 304
 305    ;[===============]
 306    ;[  GUI Objects  ]
 307    ;[===============]
 308    ;-- Modifier
 309    gui Add
 310       ,GroupBox
 311       ,x06 y10 w120 h140
 312       ,Modifier
 313
 314    static HG_CtrlModifier
 315    gui Add
 316       ,CheckBox
 317       ,x16 y30 w40 h20 vHG_CtrlModifier gHotkeyGUI_UpdateHotkey
 318       ,Ctrl
 319
 320    static HG_ShiftModifier
 321    gui Add
 322       ,CheckBox
 323       ,y+0 w40 h20 vHG_ShiftModifier gHotkeyGUI_UpdateHotkey
 324       ,Shift
 325
 326    static HG_WinModifier
 327    gui Add
 328       ,CheckBox
 329       ,y+0 w40 h20 vHG_WinModifier gHotkeyGUI_UpdateHotkey
 330       ,Win
 331
 332    static HG_AltModifier
 333    gui Add
 334       ,CheckBox
 335       ,y+0 w40 h20 vHG_AltModifier gHotkeyGUI_UpdateHotkey
 336       ,Alt
 337
 338
 339    ;-- Optional Attributes
 340    gui Add
 341       ,GroupBox
 342       ,x126 y10 w120 h140
 343       ,Optional Attributes
 344
 345    static HG_NativeOption
 346    gui Add
 347       ,CheckBox                                                                ;-- Button7
 348       ,x136 y30 w100 h20 Disabled vHG_NativeOption gHotkeyGUI_UpdateHotkey
 349       ,~ (Native)
 350
 351    static HG_WildcardOption
 352    gui Add
 353       ,CheckBox                                                                ;-- Button8
 354       ,y+0 w100 h20 Disabled vHG_WildcardOption gHotkeyGUI_UpdateHotkey
 355       ,*  (Wildcard)
 356
 357    static HG_LeftPairOption
 358    gui Add
 359       ,CheckBox                                                                ;-- Button9
 360       ,y+0 w100 h20 Disabled vHG_LeftPairOption gHotkeyGUI_LeftPair
 361       ,< (Left pair only)
 362
 363    static HG_RightPairOption
 364    gui Add
 365       ,CheckBox                                                                ;-- Button10
 366       ,y+0 w100 h20 Disabled vHG_RightPairOption gHotkeyGUI_RightPair
 367       ,> (Right pair only)
 368
 369  static HG_UpOption
 370    gui Add
 371       ,CheckBox                                                                ;-- Button11
 372       ,y+0 w100 h20 Disabled vHG_UpOption gHotkeyGUI_UpdateHotkey
 373       ,Up (Key release)
 374
 375    ;-- Enable "Optional Attributes"?
 376    if p_OptionalAttrib
 377        {
 378        GUIControl Enable,Button7
 379        GUIControl Enable,Button8
 380        GUIControl Enable,Button9
 381        GUIControl Enable,Button10
 382        GUIControl Enable,Button11
 383        }
 384
 385
 386    ;-- Keys
 387    gui Add
 388       ,GroupBox
 389       ,x6 y150 w240 h180
 390       ,Keys
 391
 392    static HG_StandardKeysView
 393    gui Add
 394       ,Radio
 395       ,x16 y170 w100 h20 vHG_StandardKeysView gHotkeyGUI_UpdateKeyList Checked
 396       ,Standard
 397
 398    static HG_FunctionKeysView
 399    gui Add
 400       ,Radio
 401       ,y+0 w100 h20 vHG_FunctionKeysView gHotkeyGUI_UpdateKeyList
 402       ,Function keys
 403
 404    static HG_NumpadKeysView
 405    gui Add
 406       ,Radio
 407       ,y+0 w100 h20 vHG_NumpadKeysView gHotkeyGUI_UpdateKeyList
 408       ,Numpad
 409
 410    static HG_MouseKeysView
 411    gui Add
 412       ,Radio
 413       ,y+0 w100 h20 vHG_MouseKeysView gHotkeyGUI_UpdateKeyList
 414       ,Mouse
 415
 416    static HG_MultimediaKeysView
 417    gui Add
 418       ,Radio
 419       ,y+0 w100 h20 vHG_MultimediaKeysView gHotkeyGUI_UpdateKeyList
 420       ,Multimedia
 421
 422    static HG_SpecialKeysView
 423    gui Add
 424       ,Radio
 425       ,y+0 w100 h20 vHG_SpecialKeysView gHotkeyGUI_UpdateKeyList
 426       ,Special
 427
 428    static HG_Key
 429    gui Add
 430       ,ListBox                                                                 ; -- ListBox1
 431       ,x116 y170 w120 h150 vHG_Key gHotkeyGUI_UpdateHotkey
 432
 433    gosub HotkeyGUI_UpdateKeyList
 434
 435
 436    ;-- Hotkey Display
 437    gui Add
 438       ,Text
 439       ,x6 y340 w40 h20
 440       ,Hotkey:
 441
 442    gui Add
 443       ,Edit                                                                    ;-- Edit1
 444       ,x+5 w190 h20 +ReadOnly
 445
 446    gui Add
 447       ,Text
 448       ,x6 y+5 w40 h20
 449       ,Desc:
 450
 451    gui Add
 452       ,Text                                                                    ;-- Static3
 453       ,x+5 w190 h20 +ReadOnly
 454       ,None
 455
 456
 457    ;-- Buttons
 458    gui Add
 459       ,Button
 460       ,x6 y400 w70 h25 gHotkeyGUI_AcceptButton +Default
 461       ,&Accept
 462
 463    gui Add
 464       ,Button
 465       ,x+5 w70 h25 gHotkeyGUIClose
 466       ,&Cancel
 467
 468
 469    ;-- Display HotkeyGUI window
 470    ;     Generated using SmartGUI Creator 4.0
 471    gui Show,,%p_Title%
 472
 473
 474    ;[=====================]
 475    ;[  Collect window ID  ]
 476    ;[=====================]
 477    gui +LastFound
 478    WinGet HotkeyGUI_hWnd,ID
 479
 480
 481    ;[=====================]
 482    ;[  Loop until window  ]
 483    ;[      is closed      ]
 484    ;[=====================]
 485    loop
 486  {
 487        sleep 250
 488    IfWinNotExist ahk_id %HotkeyGUI_hWnd%
 489            break
 490  }
 491
 492
 493    ;-- Set GUI default back to parent
 494    gui %p_ParentGUI%:Default
 495
 496
 497    ;[====================]
 498    ;[  Return to sender  ]
 499    ;[====================]
 500    ErrorLevel:=l_ErrorLevel
 501    return HG_HotKey  ;-- End of function
 502
 503
 504
 505
 506
 507    ; *****************************
 508    ; *                           *
 509    ; *                           *
 510    ; *        Subroutines        *
 511    ; *                           *
 512    ; *                           *
 513    ; *****************************
 514    ; ***********************
 515    ; *                     *
 516    ; *    Update Hotkey    *
 517    ; *                     *
 518    ; ***********************
 519    HotkeyGUI_UpdateHotkey:
 520    ;-- Set GUI default
 521    gui %l_GUI%:Default
 522
 523    ;-- Attach any messages to the current GUI
 524    gui +OwnDialogs
 525
 526    ;-- Collect form values
 527    gui Submit,NoHide
 528
 529
 530    ;-- Substitute Pause|Break for CtrlBreak?
 531    if HG_Key in Pause,Break
 532        if HG_CtrlModifier
 533            HG_Key=CtrlBreak
 534
 535
 536    ;-- Substitute CtrlBreak for Pause (Break would work OK too)
 537    if HG_Key=CtrlBreak
 538        if not HG_CtrlModifier
 539            HG_Key=Pause
 540
 541
 542    ;[================]
 543    ;[  Build Hotkey  ]
 544    ;[================]
 545    ;-- Initialize
 546    HG_Hotkey=
 547    HG_HKDesc=
 548
 549
 550    ;-- Options
 551    if HG_NativeOption
 552        HG_Hotkey:=HG_Hotkey . "~"
 553
 554    if HG_WildcardOption
 555        HG_Hotkey:=HG_Hotkey . "*"
 556
 557    if HG_LeftPairOption
 558        HG_Hotkey:=HG_Hotkey . "<"
 559
 560    if HG_RightPairOption
 561        HG_Hotkey:=HG_Hotkey . ">"
 562
 563    ;-- Modifiers
 564    if HG_CtrlModifier
 565        {
 566        HG_Hotkey:=HG_Hotkey . "^"
 567        HG_HKDesc:=HG_HKDesc . "Ctrl + "
 568        }
 569
 570    if HG_ShiftModifier
 571        {
 572        HG_Hotkey:=HG_Hotkey . "+"
 573        HG_HKDesc:=HG_HKDesc . "Shift + "
 574        }
 575
 576    if HG_WinModifier
 577        {
 578        HG_Hotkey:=HG_Hotkey . "#"
 579        HG_HKDesc:=HG_HKDesc . "Win + "
 580        }
 581
 582    if HG_AltModifier
 583        {
 584        HG_Hotkey:=HG_Hotkey . "!"
 585        HG_HKDesc:=HG_HKDesc . "Alt + "
 586        }
 587
 588    HG_Hotkey:=HG_Hotkey . HG_Key
 589    HG_HKDesc:=HG_HKDesc . HG_Key
 590  if HG_UpOption
 591  {
 592        HG_Hotkey:=HG_Hotkey . " Up"
 593   HG_HKDesc:=HG_HKDesc . " Up"
 594  }
 595    ;-- Update Hotkey and HKDescr fields
 596    GUIControl ,,Edit1,%HG_Hotkey%
 597    GUIControl ,,Static3,%HG_HKDesc%
 598
 599    ;-- Return to sender
 600    return
 601
 602
 603
 604    ; **********************
 605    ; *                    *
 606    ; *    Pair Options    *
 607    ; *                    *
 608    ; **********************
 609    HotkeyGUI_LeftPair:
 610
 611    ;-- Set GUI default
 612    gui %l_GUI%:Default
 613
 614
 615    ;-- Deselect HG_RightPairOption
 616    GUIControl ,,Button10,0
 617    gosub HotkeyGUI_UpdateHotkey
 618    return
 619
 620
 621
 622    HotkeyGUI_RightPair:
 623
 624    ;-- Set GUI default
 625    gui %l_GUI%:Default
 626
 627
 628    ;-- Deselect HG_LeftPairOption
 629    GUIControl ,,Button9,0
 630    gosub HotkeyGUI_UpdateHotkey
 631    return
 632
 633
 634    ; *************************
 635    ; *                       *
 636    ; *    Update Key List    *
 637    ; *                       *
 638    ; *************************
 639    HotkeyGUI_UpdateKeyList:
 640
 641    ;-- Set GUI default
 642    gui %l_GUI%:Default
 643
 644    ;-- Collect form values
 645    gui Submit,NoHide
 646
 647
 648    ;-- Standard
 649    if HG_StandardKeysView
 650        HG_KeyList=
 651           (ltrim join
 652            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ƒ
 653            0ƒ1ƒ2ƒ3ƒ4ƒ5ƒ6ƒ7ƒ8ƒ9ƒ0ƒ
 654            ``ƒ-ƒ=ƒ[ƒ]ƒ`\ƒ;ƒ
 655            'ƒ,ƒ.ƒ/ƒ
 656            SpaceƒTabƒEnterƒEscapeƒBackspaceƒDeleteƒ
 657            ScrollLockƒCapsLockƒNumLockƒ
 658            PrintScreenƒCtrlBreakƒPauseƒBreakƒ
 659            InsertƒHomeƒEndƒPgUpƒPgDnƒ
 660            UpƒDownƒLeftƒRightƒ
 661           )
 662
 663
 664    ;-- Function keys
 665    if HG_FunctionKeysView
 666        HG_KeyList=
 667           (ltrim join
 668            F1ƒF2ƒF3ƒF4ƒF5ƒF6ƒF7ƒF8ƒF9ƒF10ƒF11ƒF12ƒ
 669            F13ƒF14ƒF15ƒF16ƒF17ƒF18ƒF19ƒF20ƒF21ƒF22ƒF23ƒF24
 670           )
 671
 672
 673    ;-- Numpad
 674    if HG_NumpadKeysView
 675        HG_KeyList=
 676           (ltrim join
 677            NumLockƒNumpadDivƒNumpadMultƒNumpadAddƒNumpadSubƒNumpadEnterƒ
 678            NumpadDelƒNumpadInsƒNumpadClearƒNumpadUpƒNumpadDownƒNumpadLeftƒ
 679            NumpadRightƒNumpadHomeƒNumpadEndƒNumpadPgUpƒNumpadPgDnƒNumpad0ƒ
 680            Numpad1ƒNumpad2ƒNumpad3ƒNumpad4ƒNumpad5ƒNumpad6ƒNumpad7ƒNumpad8ƒ
 681            Numpad9ƒNumpadDot
 682           )
 683
 684
 685    ;-- Mouse
 686    if HG_MouseKeysView
 687        HG_KeyList=LButtonƒRButtonƒMButtonƒWheelDownƒWheelUpƒXButton1ƒXButton2
 688
 689
 690    ;-- Multimedia
 691    if HG_MultimediaKeysView
 692        HG_KeyList=
 693           (ltrim join
 694            Browser_BackƒBrowser_ForwardƒBrowser_RefreshƒBrowser_Stopƒ
 695            Browser_SearchƒBrowser_FavoritesƒBrowser_HomeƒVolume_Muteƒ
 696            Volume_DownƒVolume_UpƒMedia_NextƒMedia_PrevƒMedia_Stopƒ
 697            Media_Play_PauseƒLaunch_MailƒLaunch_MediaƒLaunch_App1ƒLaunch_App2ƒ
 698           )
 699
 700
 701    ;-- Special
 702    if HG_SpecialKeysView
 703        HG_KeyList=HelpƒSleep
 704
 705
 706    ;-- Update HG_KeyList
 707    GUIControl -Redraw,ListBox1
 708    GUIControl ,,ListBox1,%l_GUIDelimiter%%HG_KeyList%
 709    GUIControl +Redraw,ListBox1
 710
 711
 712    ;--- Reset HG_Hotkey and HG_HKDesc
 713    HG_Key=
 714    gosub HotkeyGUI_UpdateHotkey
 715
 716
 717    ;-- Return to sender
 718    return
 719
 720
 721
 722    ; ***********************
 723    ; *                     *
 724    ; *    Accept Button    *
 725    ; *                     *
 726    ; ***********************
 727    HotkeyGUI_AcceptButton:
 728
 729    ;-- Attach any messages to the current GUI
 730    gui +OwnDialogs
 731
 732
 733    ;-- Any key?
 734    if not HG_Key
 735        {
 736        MsgBox 262160
 737            ,%p_Title%
 738            ,A key must be selected.
 739        return
 740        }
 741
 742
 743    ;[===============]
 744    ;[  Limit Tests  ]
 745    ;[===============]
 746    l_ErrorLevel=0
 747    l_Limit:=p_Limit
 748
 749
 750    ;-- Loop until failure or until all tests have been performed
 751    loop
 752        {
 753        ;-- Are we done here?
 754        if l_limit<=0
 755            break
 756
 757
 758        ;-----------------
 759        ;-- Shift+Win+Alt
 760        ;-----------------
 761        if l_limit>=1024
 762            {
 763            if (HG_ShiftModifier and HG_WinModifier and HG_AltModifier)
 764                {
 765                l_Message=SHIFT+WIN+ALT keys are not allowed.
 766                l_ErrorLevel=1024
 767                break
 768                }
 769
 770            l_limit:=l_limit-1024
 771            continue
 772            }
 773
 774
 775        ;------------------
 776        ;-- Shift+Ctrl+Win
 777        ;------------------
 778        if l_limit>=512
 779            {
 780            if (HG_ShiftModifier and HG_CtrlModifier and HG_WinModifier)
 781                {
 782                l_Message=SHIFT+CTRL+WIN keys are not allowed.
 783                l_ErrorLevel=512
 784                break
 785                }
 786
 787            l_limit:=l_limit-512
 788            continue
 789            }
 790
 791
 792        ;------------------
 793        ;-- Shift+Ctrl+Alt
 794        ;------------------
 795        if l_limit>=256
 796            {
 797            if (HG_ShiftModifier and HG_CtrlModifier and HG_AltModifier)
 798                {
 799                l_Message=SHIFT+CTRL+ALT keys are not allowed.
 800                l_ErrorLevel=256
 801                break
 802                }
 803
 804            l_limit:=l_limit-256
 805            continue
 806            }
 807
 808
 809        ;-------------
 810        ;-- Shift+Win
 811        ;-------------
 812        if l_limit>=128
 813            {
 814            if (HG_ShiftModifier and HG_WinModifier)
 815                {
 816                l_Message=SHIFT+WIN keys are not allowed.
 817                l_ErrorLevel=128
 818                break
 819                }
 820
 821            l_limit:=l_limit-128
 822            continue
 823            }
 824
 825
 826        ;-------------
 827        ;-- Shift+Alt
 828        ;-------------
 829        if l_limit>=64
 830            {
 831            if (HG_ShiftModifier and HG_AltModifier)
 832                {
 833                l_Message=SHIFT+ALT keys are not allowed.
 834                l_ErrorLevel=64
 835                break
 836                }
 837
 838            l_limit:=l_limit-64
 839            continue
 840            }
 841
 842
 843        ;--------------
 844        ;-- Shift+Ctrl
 845        ;--------------
 846        if l_limit>=32
 847            {
 848            if (HG_ShiftModifier and HG_CtrlModifier)
 849                {
 850                l_Message=SHIFT+CTRL keys are not allowed.
 851                l_ErrorLevel=32
 852                break
 853                }
 854
 855            l_limit:=l_limit-32
 856            continue
 857            }
 858
 859
 860        ;------------
 861        ;-- Win only
 862        ;------------
 863        if l_limit>=16
 864            {
 865            if (HG_WinModifier
 866            and not (HG_CtrlModifier or HG_ShiftModifier or HG_AltModifier))
 867                {
 868                l_Message=WIN-only keys are not allowed.
 869                l_ErrorLevel=16
 870                break
 871                }
 872
 873            l_limit:=l_limit-16
 874            continue
 875            }
 876
 877
 878        ;------------
 879        ;-- Alt only
 880        ;------------
 881        if l_limit>=8
 882            {
 883            if (HG_AltModifier
 884            and not (HG_CtrlModifier or HG_ShiftModifier or HG_WinModifier))
 885                {
 886                l_Message=ALT-only keys are not allowed.
 887                l_ErrorLevel=8
 888                break
 889                }
 890
 891            l_limit:=l_limit-8
 892            continue
 893            }
 894
 895
 896        ;-------------
 897        ;-- Ctrl only
 898        ;-------------
 899        if l_limit>=4
 900            {
 901            if (HG_CtrlModifier
 902            and not (HG_ShiftModifier or HG_WinModifier or HG_AltModifier))
 903                {
 904                l_Message=CTRL-only keys are not allowed.
 905                l_ErrorLevel=4
 906                break
 907                }
 908
 909            l_limit:=l_limit-4
 910            continue
 911            }
 912
 913
 914        ;--------------
 915        ;-- Shift only
 916        ;--------------
 917        if l_limit>=2
 918            {
 919            if (HG_ShiftModifier
 920            and not (HG_CtrlModifier or HG_WinModifier or HG_AltModifier))
 921                {
 922                l_Message=SHIFT-only keys are not allowed.
 923                l_ErrorLevel=2
 924                break
 925                }
 926
 927            l_limit:=l_limit-2
 928            continue
 929            }
 930
 931
 932        ;--------------
 933        ;-- Unmodified
 934        ;--------------
 935        ;if l_limit>=1
 936        ;    {
 937        ;    if not (HG_CtrlModifier
 938        ;        or  HG_ShiftModifier
 939        ;        or  HG_WinModifier
 940        ;        or  HG_AltModifier)
 941        ;        {
 942        ;        l_Message=
 943        ;           (ltrim join`s
 944        ;            At least one modifier must be used.
 945        ;           )
 946
 947        ;        l_ErrorLevel=1
 948        ;        break
 949        ;        }
 950
 951        ;    l_limit:=l_limit-1
 952        ;    continue
 953        ;    }
 954        l_limit := -1
 955        }
 956
 957
 958    ;[====================]
 959    ;[  Display message?  ]
 960    ;[====================]
 961    if l_ErrorLevel
 962        if p_LimitMsg
 963            {
 964            ;-- Display message
 965            MsgBox 262160
 966                ,%p_Title%
 967                ,%l_Message%
 968
 969            ;-- Reset l_ErrorLevel
 970            l_ErrorLevel=0
 971
 972            ;-- Send 'em back
 973            return
 974            }
 975
 976
 977    ;[==================]
 978    ;[  Ok, We're done  ]
 979    ;[   Shut it done   ]
 980    ;[==================]
 981    gosub HotkeyGUIExit
 982
 983
 984    ;-- Return to sender
 985    return
 986
 987
 988
 989    ; ***********************
 990    ; *                     *
 991    ; *    Close up shop    *
 992    ; *                     *
 993    ; ***********************
 994    HotkeyGUIEscape:
 995    HotkeyGUIClose:
 996    HG_Hotkey:=""
 997    l_ErrorLevel=10003
 998
 999
1000    HotkeyGUIExit:
1001
1002;;;;;    ;-- Set GUI default (needed because of timer)
1003;;;;;    gui %l_GUI%:Default
1004
1005
1006    ;-- Enable the parent window
1007    gui %p_ParentGUI%:-Disabled
1008
1009
1010    ;-- Destroy the HotkeyGUI window so that the window can be reused
1011    gui destroy
1012
1013    return  ;-- End of subroutines
1014    }