zamaro

Untitled

Feb 27th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. #NoEnv
  2. #singleinstance force
  3. ; #Warn ; Enable warnings to assist with detecting common errors.
  4. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  5.  
  6. Process, Priority, , High
  7.  
  8. SendMode Input
  9. SetWorkingDir, %A_ScriptDir%
  10. file = %A_ScriptDir%\settings.ini
  11.  
  12. #NoEnv
  13. #singleinstance force
  14. ; #Warn ; Enable warnings to assist with detecting common errors.
  15. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  16.  
  17. Process, Priority, , High
  18.  
  19. SendMode Input
  20. SetWorkingDir, %A_ScriptDir%
  21. file = %A_ScriptDir%\settings.ini
  22.  
  23.  
  24. ButtonKeysetup:
  25. #ctrls = 1 ;How many Hotkey controls to add?
  26. Loop,% #ctrls {
  27. Gui, 3:Add, Text, xm, Enter Activation key #%A_Index%:
  28. IniRead, savedHK%A_Index%, settings.ini, Hotkeys, %A_Index%, %A_Space%
  29. If savedHK%A_Index% ;Check for saved hotkeys in INI file.
  30. Hotkey,% savedHK%A_Index%, Label%A_Index% ;Activate saved hotkeys if found.
  31. StringReplace, noMods, savedHK%A_Index%, ~ ;Remove tilde (~) and Win (#) modifiers...
  32. StringReplace, noMods, noMods, #,,UseErrorLevel ;They are incompatible with hotkey controls (cannot be shown).
  33. Gui, 3:Add, Hotkey, x+5 vHK%A_Index% gGuiLabel, %noMods% ;Add hotkey controls and show saved hotkeys.
  34. } ;Check the box if Win modifier is used.
  35. IniRead, savedHK%A_Index%, settings.ini, Hotkeys, %A_Index%, %A_Space%
  36. StringReplace, noMods, savedHK%A_Index%, ~ ;Remove tilde (~) and Win (#) modifiers...
  37. StringReplace, noMods, noMods, #,,UseErrorLevel ;They are incompatible with hotkey controls (cannot be shown).
  38. Gui, 3:Add, Hotkey, x+5 vHK%A_Index% gGuiLabel, %noMods% ;Add hotkey controls and show saved hotkeys.
  39. Gui, 3:Add, Button, , Save and Close
  40. Gui, 3:Show,,Dynamic Hotkeys
  41. return
  42.  
  43. 3ButtonSaveandClose:
  44. Gui, 3:Submit
  45. savedHK%num% := HK%num%
  46. Gui, 3:Destroy
  47. return
  48.  
  49. GuiLabel:
  50. If %A_GuiControl% in +,^,!,+^,+!,^!,+^! ;If the hotkey contains only modifiers, return to wait for a key.
  51. return
  52. If InStr(%A_GuiControl%,"vk07") ;vk07 = MenuMaskKey (see below)
  53. GuiControl,,%A_GuiControl%, % lastHK ;Reshow the hotkey, because MenuMaskKey clears it.
  54. Else
  55. validateHK(A_GuiControl)
  56. return
  57.  
  58. validateHK(GuiControl) {
  59. global lastHK
  60. Gui, Submit, NoHide
  61. lastHK := %GuiControl% ;Backup the hotkey, in case it needs to be reshown.
  62. num := SubStr(GuiControl,3) ;Get the index number of the hotkey control.
  63. If (HK%num% != "") { ;If the hotkey is not blank...
  64. StringReplace, HK%num%, HK%num%, SC15D, AppsKey ;Use friendlier names,
  65. StringReplace, HK%num%, HK%num%, SC154, PrintScreen ; instead of these scan codes.
  66. If CB%num% ; If the 'Win' box is checked, then add its modifier (#).
  67. HK%num% := "#" HK%num%
  68. If !RegExMatch(HK%num%,"[#!\^\+]") ; If the new hotkey has no modifiers, add the (~) modifier.
  69. HK%num% := "~" HK%num% ; This prevents any key from being blocked.
  70. checkDuplicateHK(num)
  71. }
  72. If (savedHK%num% || HK%num%) ;Unless both are empty,
  73. setHK(num, savedHK%num%, HK%num%) ; update INI/GUI
  74. }
  75.  
  76. checkDuplicateHK(num) {
  77. global #ctrls
  78. Loop,% #ctrls
  79. If (HK%num% = savedHK%A_Index%) {
  80. dup := A_Index
  81. Loop,6 {
  82. GuiControl,% "Disable" b:=!b, HK%dup% ;Flash the original hotkey to alert the user.
  83. Sleep,200
  84. }
  85. GuiControl,,HK%num%,% HK%num% :="" ;Delete the hotkey and clear the control.
  86. break
  87. }
  88. }
  89.  
  90. setHK(num,INI,GUI) {
  91. If INI ;If previous hotkey exists,
  92. Hotkey, %INI%, Label%num%, Off ; disable it.
  93. If GUI ;If new hotkey exists,
  94. Hotkey, %GUI%, Label%num%, On ; enable it.
  95. IniWrite,% GUI ? GUI:null, settings.ini, Hotkeys, %num%
  96. savedHK%num% := HK%num%
  97. }
  98.  
  99. #MenuMaskKey vk07 ;Requires AHK_L 38+
  100. #If ctrl := HotkeyCtrlHasFocus()
  101. *AppsKey:: ;Add support for these special keys,
  102. *BackSpace:: ; which the hotkey control does not normally allow.
  103. *Delete::
  104. *Enter::
  105. *Escape::
  106. *Pause::
  107. *PrintScreen::
  108. *Space::
  109. *Tab::
  110. modifier := ""
  111. If GetKeyState("Shift","P")
  112. modifier .= "+"
  113. If GetKeyState("Ctrl","P")
  114. modifier .= "^"
  115. If GetKeyState("Alt","P")
  116. modifier .= "!"
  117. Gui, Submit, NoHide ;If BackSpace is the first key press, Gui has never been submitted.
  118. If (A_ThisHotkey == "*BackSpace" && %ctrl% && !modifier) ;If the control has text but no modifiers held,
  119. GuiControl,,%ctrl% ; allow BackSpace to clear that text.
  120. Else ;Otherwise,
  121. GuiControl,,%ctrl%, % modifier SubStr(A_ThisHotkey,2) ; show the hotkey.
  122. validateHK(ctrl)
  123. return
  124. #If
  125.  
  126. HotkeyCtrlHasFocus() {
  127. GuiControlGet, ctrl, Focus ;ClassNN
  128. If InStr(ctrl,"hotkey") {
  129. GuiControlGet, ctrl, FocusV ;Associated variable
  130. Return, ctrl
  131. }
  132. }
  133.  
  134.  
  135. F1::
  136. return
  137.  
  138. label1:
  139.  
  140.  
  141. return
Advertisement
Add Comment
Please, Sign In to add comment