Advertisement
InAbstenia

Holder

Apr 11th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. #Requires Autohotkey v2.1-alpha.14
  2. #SingleInstance Force
  3. #Include <TapHoldManager>
  4. #Include <Notify>
  5. #Include <All>
  6. #Include _zPopMenu.ahk
  7.  
  8. TraySetIcon(A_ScriptDir "/Lib/Icons/hKey.png")
  9.  
  10. THM := TapHoldManager()
  11. THM.Add("F14", Layer1)
  12. THM.Add("F13", Layer2)
  13. THM.Add("F12", Layer3)
  14.  
  15. ;/////////////////////////
  16.  
  17. #HotIf GetKeyState("F14", "P")
  18. {
  19. WheelUp:: Send("{LControl Down}{Tab}{LControl Up}")
  20. WheelDown:: Send("{LControl Down}{LShift Down}{Tab}{LShift Up}{LControl Up}")
  21. Delete:: Send("{BackSpace}")
  22. ^C:: Send("{LControl Down}{a}{LControl Up}")
  23. ^V:: Send("{F20}")
  24. XButton2:: Send("{LControl Down}{y}{LControl Up}")
  25. XButton1:: Send("{LControl Down}{z}{LControl Up}")
  26. ^W:: Send("{LControl Down}{LShift Down}{t}{LShift Up}{LControl Up}")
  27. }
  28. #HotIf GetKeyState("F13", "P")
  29. {
  30. WheelUp:: Send("{Up}")
  31. WheelDown:: Send("{Down}")
  32. Delete:: Send("{LControl Down}{Backspace}{LControl Up}")
  33. ^C:: Send("{Up}")
  34. ^V:: Send("{LWin Down}{c}{LWin Up}")
  35. XButton2:: Send("{Left}")
  36. XButton1:: Send("{F23}")
  37. ^W:: Send("{LWin Down}{g}{LWin Up}")
  38. RButton:: (() => ShowMain(1))()
  39. }
  40. #HotIf GetKeyState("F12", "P")
  41. {
  42. WheelUp:: (() => (Layer.Notify("Home"), Send("{LControl Down}{Home}{LControl Up}")))()
  43. WheelDown:: (() => (Layer.Notify("End"), Send("{LControl Down}{End}{LControl Up}")))()
  44. a:: (() => (Layer.Notify("Opened App 1"), Send("{LWin Down}{1}{LWin Up}")))()
  45. s:: (() => (Layer.Notify("Opened App 2"), Send("{LWin Down}{2}{LWin Up}")))()
  46. d:: (() => (Layer.Notify("Opened App 3"), Send("{LWin Down}{3}{LWin Up}")))()
  47. f:: (() => (Layer.Notify("Opened App 4"), Send("{LWin Down}{4}{LWin Up}")))()
  48. }
  49. #HotIf
  50.  
  51. ;/////////////////////////
  52.  
  53. class Layer {
  54. static currentLayerName := ""
  55. static currentLayerKey := ""
  56.  
  57. static SetLayer(layerKey) {
  58. this.currentLayerKey := layerKey
  59. try {
  60. Error()
  61. } catch Error as e {
  62. if (e.Stack) {
  63. stack := StrSplit(e.Stack, "`n")
  64. if (stack.Length > 2) {
  65. callerLine := stack[2]
  66. if RegExMatch(callerLine, "Layer(\d+)", &match) ;/// Extract layer number instead of function name ///
  67. this.currentLayerName := "Layer " match[1] ;/// Format as "Layer N" ///
  68. }
  69. }
  70. }
  71. }
  72.  
  73. static CheckKeyState(key) {
  74. if GetKeyState(key, "P") {
  75. try {
  76. this.Release()
  77. } catch Error as e {
  78. }
  79. }
  80. }
  81.  
  82. static Notify(action) {
  83. layerPrefix := this.currentLayerName ? this.currentLayerName . ": " : ""
  84. message := layerPrefix . action
  85. Notify.Show(message, , , , , "dur=1 pos=bl tag=" message " ts=10")
  86. }
  87.  
  88. static NotifyHold(message, key) {
  89. layerPrefix := this.currentLayerName ? this.currentLayerName . ": " : ""
  90. Notify.Show(layerPrefix . message, , , , , "dur=0 pos=bl tag=" message " ts=10")
  91. KeyWait(key)
  92. Notify.Destroy(message)
  93. }
  94.  
  95. static Hold() {
  96. key := this.currentLayerKey
  97. if (GetKeyState(key, "P")) {
  98. this.NotifyHold("Hold", key)
  99. startTime := A_TickCount
  100. KeyWait(key)
  101. elapsedTime := A_TickCount - startTime
  102. if (elapsedTime >= 250) {
  103. this.Notify("Released")
  104. }
  105. }
  106. }
  107.  
  108. static Release() {
  109. try {
  110. Send("{F12 Up}{F13 Up}{F14 Up}")
  111. Send("{LControl Up}{RControl Up}")
  112. Send("{LShift Up}{RShift Up}")
  113. Send("{LWin Up}{RWin Up}")
  114. Send("{LAlt Up}{RAlt Up}")
  115. }
  116. }
  117. }
  118.  
  119. ;/////////////////////////
  120.  
  121. Layer1(IsHold, Taps, State) {
  122. Layer.SetLayer("F14")
  123. switch {
  124. case IsHold:
  125. Layer.Hold()
  126. case Taps = 1:
  127. if (State = -1)
  128. Layer.Notify("Tap")
  129. Command.Run()
  130. case Taps = 2:
  131. Layer.Notify("TapHold")
  132. SoundBeep(500, 100)
  133. KeyWait("F14", "L")
  134. if (State = -1)
  135. Layer.Notify("TapHold")
  136. case Taps = 3:
  137. Command.SnippingTool()
  138. Layer.Notify("TripleTap")
  139. case Taps = 4:
  140. Command.RestartExplorer()
  141. Layer.Notify("QuadrupleTap")
  142. Beep.RunSound()
  143. }
  144. }
  145.  
  146. Layer2(IsHold, Taps, State) {
  147. Layer.SetLayer("F13")
  148. switch {
  149. case IsHold:
  150. Layer.Hold()
  151. case Taps = 1:
  152. if (State = -1)
  153. Layer.Notify("Tap")
  154. Command.Run()
  155. case Taps = 2:
  156. Layer.Notify("TapHold")
  157. SoundBeep(500, 100)
  158. KeyWait("F13", "L")
  159. if (State = -1)
  160. Layer.Notify("TapHold")
  161. case Taps = 3:
  162. Command.SnippingTool()
  163. Layer.Notify("TripleTap")
  164. case Taps = 4:
  165. Command.RestartExplorer()
  166. Layer.Notify("QuadrupleTap")
  167. Beep.RunSound()
  168. }
  169. }
  170.  
  171. Layer3(IsHold, Taps, State) {
  172. Layer.SetLayer("F12")
  173. switch {
  174. case IsHold:
  175. switch {
  176. case (Taps = 2 && State = 0):
  177. Layer.Notify("TapHold")
  178. WindowState.UnMinimize()
  179. case (Taps = 3 && State = 0):
  180. Layer.Notify("TapTapHold")
  181. WindowState.UnMinimize()
  182. }
  183. Layer.Hold()
  184. case Taps = 1:
  185. if (State = -1)
  186. WindowState.Minimize()
  187. Layer.Notify("Tap")
  188. case Taps = 2:
  189. Layer.Notify('DoubleTap')
  190. case Taps = 3:
  191. Layer.Notify('TripleTap')
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement