/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. ;-------------------------------------------------------------------------------
  174. HotkeyGUI(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. ;[ Parameters ]
  192. ;[ (Set defaults) ]
  193. ;[==================]
  194. ;-- GUI
  195. p_GUI=%p_GUI% ;-- AutoTrim
  196. if p_GUI is not Integer
  197. p_GUI=81
  198. else
  199. if p_GUI not between 1 and 99
  200. p_GUI=81
  201. ;-- Parent GUI
  202. p_ParentGUI=%p_ParentGUI% ;-- AutoTrim
  203. if p_ParentGUI is not Integer
  204. p_ParentGUI=1
  205. else
  206. if p_ParentGUI not between 1 and 99
  207. p_ParentGUI=1
  208. ;-- Title
  209. p_Title=%p_Title% ;-- AutoTrim
  210. if strlen(p_Title)=0
  211. p_Title:=l_ScriptName . " - Select Hotkey"
  212. else
  213. {
  214. ;-- Append to script name if p_title begins with "++"?
  215. if instr(p_Title,"++")=1
  216. {
  217. StringTrimLeft p_Title,p_Title,2
  218. p_Title:=l_ScriptName . A_Space . p_Title
  219. }
  220. }
  221. ;-- Limit
  222. p_Limit=%p_Limit% ;-- AutoTrim
  223. if p_Limit is not Integer
  224. p_Limit=0
  225. else
  226. if p_Limit not between 0 and 2047
  227. p_Limit=0
  228. ;-- LimitMsg
  229. p_LimitMsg=%p_LimitMsg% ;-- AutoTrim
  230. if p_LimitMsg is not Integer
  231. p_LimitMsg:=true
  232. else
  233. if p_LimitMsg not between 0 and 1
  234. p_LimitMsg:=true
  235. ;-- OptionalAttrib
  236. p_OptionalAttrib=%p_OptionalAttrib% ;-- AutoTrim
  237. if p_OptionalAttrib is not Integer
  238. p_OptionalAttrib:=true
  239. else
  240. if p_OptionalAttrib not between 0 and 1
  241. p_OptionalAttrib:=true
  242. HG_Filter := p_filter
  243. HG_Exclude := p_exclude
  244. ;[=========================]
  245. ;[ Find available window ]
  246. ;[ (Starting with p_GUI) ]
  247. ;[=========================]
  248. l_GUI:=p_GUI
  249. loop
  250. {
  251. ;-- Window available?
  252. gui %l_GUI%:+LastFoundExist
  253. IfWinNotExist
  254. break
  255. ;-- Nothing available?
  256. if l_GUI=99
  257. {
  258. MsgBox 262160
  259. ,HotkeyGUI Error
  260. ,Unable to create HotkeyGUI window. GUI windows %p_GUI% to 99 are already in use.
  261. ErrorLevel=9999
  262. return ""
  263. }
  264. ;-- Increment window
  265. l_GUI++
  266. }
  267. ;[===================]
  268. ;[ Set GUI default ]
  269. ;[===================]
  270. gui %l_GUI%:Default
  271. ;[=====================]
  272. ;[ Build/Display GUI ]
  273. ;[=====================]
  274. ;-- Disable parent GUI
  275. gui %p_ParentGUI%:+Disabled
  276. ;-- Set ownership
  277. gui +Owner%p_ParentGUI%
  278. ;-- Set margins
  279. gui Margin,6,6
  280. ;-- GUI options
  281. gui -MinimizeBox +LabelHotkeyGUI +Delimiter%l_GUIDelimiter%
  282. ;[===============]
  283. ;[ GUI Objects ]
  284. ;[===============]
  285. ;-- Modifier
  286. gui Add
  287. ,GroupBox
  288. ,x06 y10 w120 h140
  289. ,Modifier
  290. static HG_CtrlModifier
  291. gui Add
  292. ,CheckBox
  293. ,x16 y30 w40 h20 vHG_CtrlModifier gHotkeyGUI_UpdateHotkey
  294. ,Ctrl
  295. static HG_ShiftModifier
  296. gui Add
  297. ,CheckBox
  298. ,y+0 w40 h20 vHG_ShiftModifier gHotkeyGUI_UpdateHotkey
  299. ,Shift
  300. static HG_WinModifier
  301. gui Add
  302. ,CheckBox
  303. ,y+0 w40 h20 vHG_WinModifier gHotkeyGUI_UpdateHotkey
  304. ,Win
  305. static HG_AltModifier
  306. gui Add
  307. ,CheckBox
  308. ,y+0 w40 h20 vHG_AltModifier gHotkeyGUI_UpdateHotkey
  309. ,Alt
  310. ;-- Optional Attributes
  311. gui Add
  312. ,GroupBox
  313. ,x126 y10 w120 h140
  314. ,Optional Attributes
  315. static HG_NativeOption
  316. gui Add
  317. ,CheckBox ;-- Button7
  318. ,x136 y30 w100 h20 Disabled vHG_NativeOption gHotkeyGUI_UpdateHotkey
  319. ,~ (Native)
  320. static HG_WildcardOption
  321. gui Add
  322. ,CheckBox ;-- Button8
  323. ,y+0 w100 h20 Disabled vHG_WildcardOption gHotkeyGUI_UpdateHotkey
  324. ,* (Wildcard)
  325. static HG_LeftPairOption
  326. gui Add
  327. ,CheckBox ;-- Button9
  328. ,y+0 w100 h20 Disabled vHG_LeftPairOption gHotkeyGUI_LeftPair
  329. ,< (Left pair only)
  330. static HG_RightPairOption
  331. gui Add
  332. ,CheckBox ;-- Button10
  333. ,y+0 w100 h20 Disabled vHG_RightPairOption gHotkeyGUI_RightPair
  334. ,> (Right pair only)
  335. static HG_UpOption
  336. gui Add
  337. ,CheckBox ;-- Button11
  338. ,y+0 w100 h20 Disabled vHG_UpOption gHotkeyGUI_UpdateHotkey
  339. ,Up (Key release)
  340. ;-- Enable "Optional Attributes"?
  341. if p_OptionalAttrib
  342. {
  343. GUIControl Enable,Button7
  344. GUIControl Enable,Button8
  345. GUIControl Enable,Button9
  346. GUIControl Enable,Button10
  347. GUIControl Enable,Button11
  348. }
  349. ;-- Keys
  350. gui Add
  351. ,GroupBox
  352. ,x6 y150 w240 h180
  353. ,Keys
  354. static HG_StandardKeysView
  355. gui Add
  356. ,Radio
  357. ,x16 y170 w100 h20 vHG_StandardKeysView gHotkeyGUI_UpdateKeyList Checked
  358. ,Standard
  359. static HG_FunctionKeysView
  360. gui Add
  361. ,Radio
  362. ,y+0 w100 h20 vHG_FunctionKeysView gHotkeyGUI_UpdateKeyList
  363. ,Function keys
  364. static HG_NumpadKeysView
  365. gui Add
  366. ,Radio
  367. ,y+0 w100 h20 vHG_NumpadKeysView gHotkeyGUI_UpdateKeyList
  368. ,Numpad
  369. static HG_MouseKeysView
  370. gui Add
  371. ,Radio
  372. ,y+0 w100 h20 vHG_MouseKeysView gHotkeyGUI_UpdateKeyList
  373. ,Mouse
  374. static HG_MultimediaKeysView
  375. gui Add
  376. ,Radio
  377. ,y+0 w100 h20 vHG_MultimediaKeysView gHotkeyGUI_UpdateKeyList
  378. ,Multimedia
  379. static HG_SpecialKeysView
  380. gui Add
  381. ,Radio
  382. ,y+0 w100 h20 vHG_SpecialKeysView gHotkeyGUI_UpdateKeyList
  383. ,Special
  384. static HG_Key
  385. gui Add
  386. ,ListBox ; -- ListBox1
  387. ,x116 y170 w120 h150 vHG_Key gHotkeyGUI_UpdateHotkey
  388. gosub HotkeyGUI_UpdateKeyList
  389. ;-- Hotkey Display
  390. gui Add
  391. ,Text
  392. ,x6 y340 w40 h20
  393. ,Hotkey:
  394. gui Add
  395. ,Edit ;-- Edit1
  396. ,x+5 w190 h20 +ReadOnly
  397. gui Add
  398. ,Text
  399. ,x6 y+5 w40 h20
  400. ,Desc:
  401. gui Add
  402. ,Text ;-- Static3
  403. ,x+5 w190 h20 +ReadOnly
  404. ,None
  405. ;-- Buttons
  406. gui Add
  407. ,Button
  408. ,x6 y400 w70 h25 gHotkeyGUI_AcceptButton +Default
  409. ,&Accept
  410. gui Add
  411. ,Button
  412. ,x+5 w70 h25 gHotkeyGUIClose
  413. ,&Cancel
  414. ;-- Display HotkeyGUI window
  415. ; Generated using SmartGUI Creator 4.0
  416. gui Show,,%p_Title%
  417. ;[=====================]
  418. ;[ Collect window ID ]
  419. ;[=====================]
  420. gui +LastFound
  421. WinGet HotkeyGUI_hWnd,ID
  422. ;[=====================]
  423. ;[ Loop until window ]
  424. ;[ is closed ]
  425. ;[=====================]
  426. loop
  427. {
  428. sleep 250
  429. IfWinNotExist ahk_id %HotkeyGUI_hWnd%
  430. break
  431. }
  432. ;-- Set GUI default back to parent
  433. gui %p_ParentGUI%:Default
  434. ;[====================]
  435. ;[ Return to sender ]
  436. ;[====================]
  437. ErrorLevel:=l_ErrorLevel
  438. return HG_HotKey ;-- End of function
  439. ; *****************************
  440. ; * *
  441. ; * *
  442. ; * Subroutines *
  443. ; * *
  444. ; * *
  445. ; *****************************
  446. ; ***********************
  447. ; * *
  448. ; * Update Hotkey *
  449. ; * *
  450. ; ***********************
  451. HotkeyGUI_UpdateHotkey:
  452. ;-- Set GUI default
  453. gui %l_GUI%:Default
  454. ;-- Attach any messages to the current GUI
  455. gui +OwnDialogs
  456. ;-- Collect form values
  457. gui Submit,NoHide
  458. ;-- Substitute Pause|Break for CtrlBreak?
  459. if HG_Key in Pause,Break
  460. if HG_CtrlModifier
  461. HG_Key=CtrlBreak
  462. ;-- Substitute CtrlBreak for Pause (Break would work OK too)
  463. if HG_Key=CtrlBreak
  464. if not HG_CtrlModifier
  465. HG_Key=Pause
  466. ;[================]
  467. ;[ Build Hotkey ]
  468. ;[================]
  469. ;-- Initialize
  470. HG_Hotkey=
  471. HG_HKDesc=
  472. ;-- Options
  473. if HG_NativeOption
  474. HG_Hotkey:=HG_Hotkey . "~"
  475. if HG_WildcardOption
  476. HG_Hotkey:=HG_Hotkey . "*"
  477. if HG_LeftPairOption
  478. HG_Hotkey:=HG_Hotkey . "<"
  479. if HG_RightPairOption
  480. HG_Hotkey:=HG_Hotkey . ">"
  481. ;-- Modifiers
  482. if HG_CtrlModifier
  483. {
  484. HG_Hotkey:=HG_Hotkey . "^"
  485. HG_HKDesc:=HG_HKDesc . "Ctrl + "
  486. }
  487. if HG_ShiftModifier
  488. {
  489. HG_Hotkey:=HG_Hotkey . "+"
  490. HG_HKDesc:=HG_HKDesc . "Shift + "
  491. }
  492. if HG_WinModifier
  493. {
  494. HG_Hotkey:=HG_Hotkey . "#"
  495. HG_HKDesc:=HG_HKDesc . "Win + "
  496. }
  497. if HG_AltModifier
  498. {
  499. HG_Hotkey:=HG_Hotkey . "!"
  500. HG_HKDesc:=HG_HKDesc . "Alt + "
  501. }
  502. HG_Hotkey:=HG_Hotkey . HG_Key
  503. HG_HKDesc:=HG_HKDesc . HG_Key
  504. if HG_UpOption
  505. {
  506. HG_Hotkey:=HG_Hotkey . " Up"
  507. HG_HKDesc:=HG_HKDesc . " Up"
  508. }
  509. ;-- Update Hotkey and HKDescr fields
  510. GUIControl ,,Edit1,%HG_Hotkey%
  511. GUIControl ,,Static3,%HG_HKDesc%
  512. ;-- Return to sender
  513. return
  514. ; **********************
  515. ; * *
  516. ; * Pair Options *
  517. ; * *
  518. ; **********************
  519. HotkeyGUI_LeftPair:
  520. ;-- Set GUI default
  521. gui %l_GUI%:Default
  522. ;-- Deselect HG_RightPairOption
  523. GUIControl ,,Button10,0
  524. gosub HotkeyGUI_UpdateHotkey
  525. return
  526. HotkeyGUI_RightPair:
  527. ;-- Set GUI default
  528. gui %l_GUI%:Default
  529. ;-- Deselect HG_LeftPairOption
  530. GUIControl ,,Button9,0
  531. gosub HotkeyGUI_UpdateHotkey
  532. return
  533. ; *************************
  534. ; * *
  535. ; * Update Key List *
  536. ; * *
  537. ; *************************
  538. HotkeyGUI_UpdateKeyList:
  539. ;-- Set GUI default
  540. gui %l_GUI%:Default
  541. ;-- Collect form values
  542. gui Submit,NoHide
  543. ;-- Standard
  544. if HG_StandardKeysView
  545. HG_KeyList=
  546. (ltrim join
  547. 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ƒ
  548. 0ƒ1ƒ2ƒ3ƒ4ƒ5ƒ6ƒ7ƒ8ƒ9ƒ0ƒ
  549. ``ƒ-ƒ=ƒ[ƒ]ƒ`\ƒ;ƒ
  550. 'ƒ,ƒ.ƒ/ƒ
  551. SpaceƒTabƒEnterƒEscapeƒBackspaceƒDeleteƒ
  552. ScrollLockƒCapsLockƒNumLockƒ
  553. PrintScreenƒCtrlBreakƒPauseƒBreakƒ
  554. InsertƒHomeƒEndƒPgUpƒPgDnƒ
  555. UpƒDownƒLeftƒRightƒ
  556. )
  557. ;-- Function keys
  558. if HG_FunctionKeysView
  559. HG_KeyList=
  560. (ltrim join
  561. F1ƒF2ƒF3ƒF4ƒF5ƒF6ƒF7ƒF8ƒF9ƒF10ƒF11ƒF12ƒ
  562. F13ƒF14ƒF15ƒF16ƒF17ƒF18ƒF19ƒF20ƒF21ƒF22ƒF23ƒF24
  563. )
  564. ;-- Numpad
  565. if HG_NumpadKeysView
  566. HG_KeyList=
  567. (ltrim join
  568. NumLockƒNumpadDivƒNumpadMultƒNumpadAddƒNumpadSubƒNumpadEnterƒ
  569. NumpadDelƒNumpadInsƒNumpadClearƒNumpadUpƒNumpadDownƒNumpadLeftƒ
  570. NumpadRightƒNumpadHomeƒNumpadEndƒNumpadPgUpƒNumpadPgDnƒNumpad0ƒ
  571. Numpad1ƒNumpad2ƒNumpad3ƒNumpad4ƒNumpad5ƒNumpad6ƒNumpad7ƒNumpad8ƒ
  572. Numpad9ƒNumpadDot
  573. )
  574. ;-- Mouse
  575. if HG_MouseKeysView
  576. HG_KeyList=LButtonƒRButtonƒMButtonƒWheelDownƒWheelUpƒXButton1ƒXButton2
  577. ;-- Multimedia
  578. if HG_MultimediaKeysView
  579. HG_KeyList=
  580. (ltrim join
  581. Browser_BackƒBrowser_ForwardƒBrowser_RefreshƒBrowser_Stopƒ
  582. Browser_SearchƒBrowser_FavoritesƒBrowser_HomeƒVolume_Muteƒ
  583. Volume_DownƒVolume_UpƒMedia_NextƒMedia_PrevƒMedia_Stopƒ
  584. Media_Play_PauseƒLaunch_MailƒLaunch_MediaƒLaunch_App1ƒLaunch_App2ƒ
  585. )
  586. ;-- Special
  587. if HG_SpecialKeysView
  588. HG_KeyList=HelpƒSleep
  589. ;-- Update HG_KeyList
  590. GUIControl -Redraw,ListBox1
  591. GUIControl ,,ListBox1,%l_GUIDelimiter%%HG_KeyList%
  592. GUIControl +Redraw,ListBox1
  593. ;--- Reset HG_Hotkey and HG_HKDesc
  594. HG_Key=
  595. gosub HotkeyGUI_UpdateHotkey
  596. ;-- Return to sender
  597. return
  598. ; ***********************
  599. ; * *
  600. ; * Accept Button *
  601. ; * *
  602. ; ***********************
  603. HotkeyGUI_AcceptButton:
  604. ;-- Attach any messages to the current GUI
  605. gui +OwnDialogs
  606. ;-- Any key?
  607. if not HG_Key
  608. {
  609. MsgBox 262160
  610. ,%p_Title%
  611. ,A key must be selected.
  612. return
  613. }
  614. ;[===============]
  615. ;[ Limit Tests ]
  616. ;[===============]
  617. l_ErrorLevel=0
  618. l_Limit:=p_Limit
  619. ;-- Loop until failure or until all tests have been performed
  620. loop
  621. {
  622. ;-- Are we done here?
  623. if l_limit<=0
  624. break
  625. ;-----------------
  626. ;-- Shift+Win+Alt
  627. ;-----------------
  628. if l_limit>=1024
  629. {
  630. if (HG_ShiftModifier and HG_WinModifier and HG_AltModifier)
  631. {
  632. l_Message=SHIFT+WIN+ALT keys are not allowed.
  633. l_ErrorLevel=1024
  634. break
  635. }
  636. l_limit:=l_limit-1024
  637. continue
  638. }
  639. ;------------------
  640. ;-- Shift+Ctrl+Win
  641. ;------------------
  642. if l_limit>=512
  643. {
  644. if (HG_ShiftModifier and HG_CtrlModifier and HG_WinModifier)
  645. {
  646. l_Message=SHIFT+CTRL+WIN keys are not allowed.
  647. l_ErrorLevel=512
  648. break
  649. }
  650. l_limit:=l_limit-512
  651. continue
  652. }
  653. ;------------------
  654. ;-- Shift+Ctrl+Alt
  655. ;------------------
  656. if l_limit>=256
  657. {
  658. if (HG_ShiftModifier and HG_CtrlModifier and HG_AltModifier)
  659. {
  660. l_Message=SHIFT+CTRL+ALT keys are not allowed.
  661. l_ErrorLevel=256
  662. break
  663. }
  664. l_limit:=l_limit-256
  665. continue
  666. }
  667. ;-------------
  668. ;-- Shift+Win
  669. ;-------------
  670. if l_limit>=128
  671. {
  672. if (HG_ShiftModifier and HG_WinModifier)
  673. {
  674. l_Message=SHIFT+WIN keys are not allowed.
  675. l_ErrorLevel=128
  676. break
  677. }
  678. l_limit:=l_limit-128
  679. continue
  680. }
  681. ;-------------
  682. ;-- Shift+Alt
  683. ;-------------
  684. if l_limit>=64
  685. {
  686. if (HG_ShiftModifier and HG_AltModifier)
  687. {
  688. l_Message=SHIFT+ALT keys are not allowed.
  689. l_ErrorLevel=64
  690. break
  691. }
  692. l_limit:=l_limit-64
  693. continue
  694. }
  695. ;--------------
  696. ;-- Shift+Ctrl
  697. ;--------------
  698. if l_limit>=32
  699. {
  700. if (HG_ShiftModifier and HG_CtrlModifier)
  701. {
  702. l_Message=SHIFT+CTRL keys are not allowed.
  703. l_ErrorLevel=32
  704. break
  705. }
  706. l_limit:=l_limit-32
  707. continue
  708. }
  709. ;------------
  710. ;-- Win only
  711. ;------------
  712. if l_limit>=16
  713. {
  714. if (HG_WinModifier
  715. and not (HG_CtrlModifier or HG_ShiftModifier or HG_AltModifier))
  716. {
  717. l_Message=WIN-only keys are not allowed.
  718. l_ErrorLevel=16
  719. break
  720. }
  721. l_limit:=l_limit-16
  722. continue
  723. }
  724. ;------------
  725. ;-- Alt only
  726. ;------------
  727. if l_limit>=8
  728. {
  729. if (HG_AltModifier
  730. and not (HG_CtrlModifier or HG_ShiftModifier or HG_WinModifier))
  731. {
  732. l_Message=ALT-only keys are not allowed.
  733. l_ErrorLevel=8
  734. break
  735. }
  736. l_limit:=l_limit-8
  737. continue
  738. }
  739. ;-------------
  740. ;-- Ctrl only
  741. ;-------------
  742. if l_limit>=4
  743. {
  744. if (HG_CtrlModifier
  745. and not (HG_ShiftModifier or HG_WinModifier or HG_AltModifier))
  746. {
  747. l_Message=CTRL-only keys are not allowed.
  748. l_ErrorLevel=4
  749. break
  750. }
  751. l_limit:=l_limit-4
  752. continue
  753. }
  754. ;--------------
  755. ;-- Shift only
  756. ;--------------
  757. if l_limit>=2
  758. {
  759. if (HG_ShiftModifier
  760. and not (HG_CtrlModifier or HG_WinModifier or HG_AltModifier))
  761. {
  762. l_Message=SHIFT-only keys are not allowed.
  763. l_ErrorLevel=2
  764. break
  765. }
  766. l_limit:=l_limit-2
  767. continue
  768. }
  769. ;--------------
  770. ;-- Unmodified
  771. ;--------------
  772. ;if l_limit>=1
  773. ; {
  774. ; if not (HG_CtrlModifier
  775. ; or HG_ShiftModifier
  776. ; or HG_WinModifier
  777. ; or HG_AltModifier)
  778. ; {
  779. ; l_Message=
  780. ; (ltrim join`s
  781. ; At least one modifier must be used.
  782. ; )
  783. ; l_ErrorLevel=1
  784. ; break
  785. ; }
  786. ; l_limit:=l_limit-1
  787. ; continue
  788. ; }
  789. l_limit := -1
  790. }
  791. ;[====================]
  792. ;[ Display message? ]
  793. ;[====================]
  794. if l_ErrorLevel
  795. if p_LimitMsg
  796. {
  797. ;-- Display message
  798. MsgBox 262160
  799. ,%p_Title%
  800. ,%l_Message%
  801. ;-- Reset l_ErrorLevel
  802. l_ErrorLevel=0
  803. ;-- Send 'em back
  804. return
  805. }
  806. ;[==================]
  807. ;[ Ok, We're done ]
  808. ;[ Shut it done ]
  809. ;[==================]
  810. gosub HotkeyGUIExit
  811. ;-- Return to sender
  812. return
  813. ; ***********************
  814. ; * *
  815. ; * Close up shop *
  816. ; * *
  817. ; ***********************
  818. HotkeyGUIEscape:
  819. HotkeyGUIClose:
  820. HG_Hotkey:=""
  821. l_ErrorLevel=10003
  822. HotkeyGUIExit:
  823. ;;;;; ;-- Set GUI default (needed because of timer)
  824. ;;;;; gui %l_GUI%:Default
  825. ;-- Enable the parent window
  826. gui %p_ParentGUI%:-Disabled
  827. ;-- Destroy the HotkeyGUI window so that the window can be reused
  828. gui destroy
  829. return ;-- End of subroutines
  830. }