Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires Autohotkey v2.1-alpha.14
- #SingleInstance Force
- #Include <TapHoldManager>
- #Include <Notify>
- #Include <All>
- #Include _zPopMenu.ahk
- TraySetIcon(A_ScriptDir "/Lib/Icons/hKey.png")
- THM := TapHoldManager()
- THM.Add("F14", Layer1)
- THM.Add("F13", Layer2)
- THM.Add("F12", Layer3)
- ;/////////////////////////
- #HotIf GetKeyState("F14", "P")
- {
- WheelUp:: Send("{LControl Down}{Tab}{LControl Up}")
- WheelDown:: Send("{LControl Down}{LShift Down}{Tab}{LShift Up}{LControl Up}")
- Delete:: Send("{BackSpace}")
- ^C:: Send("{LControl Down}{a}{LControl Up}")
- ^V:: Send("{F20}")
- XButton2:: Send("{LControl Down}{y}{LControl Up}")
- XButton1:: Send("{LControl Down}{z}{LControl Up}")
- ^W:: Send("{LControl Down}{LShift Down}{t}{LShift Up}{LControl Up}")
- }
- #HotIf GetKeyState("F13", "P")
- {
- WheelUp:: Send("{Up}")
- WheelDown:: Send("{Down}")
- Delete:: Send("{LControl Down}{Backspace}{LControl Up}")
- ^C:: Send("{Up}")
- ^V:: Send("{LWin Down}{c}{LWin Up}")
- XButton2:: Send("{Left}")
- XButton1:: Send("{F23}")
- ^W:: Send("{LWin Down}{g}{LWin Up}")
- RButton:: (() => ShowMain(1))()
- }
- #HotIf GetKeyState("F12", "P")
- {
- WheelUp:: (() => (Layer.Notify("Home"), Send("{LControl Down}{Home}{LControl Up}")))()
- WheelDown:: (() => (Layer.Notify("End"), Send("{LControl Down}{End}{LControl Up}")))()
- a:: (() => (Layer.Notify("Opened App 1"), Send("{LWin Down}{1}{LWin Up}")))()
- s:: (() => (Layer.Notify("Opened App 2"), Send("{LWin Down}{2}{LWin Up}")))()
- d:: (() => (Layer.Notify("Opened App 3"), Send("{LWin Down}{3}{LWin Up}")))()
- f:: (() => (Layer.Notify("Opened App 4"), Send("{LWin Down}{4}{LWin Up}")))()
- }
- #HotIf
- ;/////////////////////////
- class Layer {
- static currentLayerName := ""
- static currentLayerKey := ""
- static SetLayer(layerKey) {
- this.currentLayerKey := layerKey
- try {
- Error()
- } catch Error as e {
- if (e.Stack) {
- stack := StrSplit(e.Stack, "`n")
- if (stack.Length > 2) {
- callerLine := stack[2]
- if RegExMatch(callerLine, "Layer(\d+)", &match) ;/// Extract layer number instead of function name ///
- this.currentLayerName := "Layer " match[1] ;/// Format as "Layer N" ///
- }
- }
- }
- }
- static CheckKeyState(key) {
- if GetKeyState(key, "P") {
- try {
- this.Release()
- } catch Error as e {
- }
- }
- }
- static Notify(action) {
- layerPrefix := this.currentLayerName ? this.currentLayerName . ": " : ""
- message := layerPrefix . action
- Notify.Show(message, , , , , "dur=1 pos=bl tag=" message " ts=10")
- }
- static NotifyHold(message, key) {
- layerPrefix := this.currentLayerName ? this.currentLayerName . ": " : ""
- Notify.Show(layerPrefix . message, , , , , "dur=0 pos=bl tag=" message " ts=10")
- KeyWait(key)
- Notify.Destroy(message)
- }
- static Hold() {
- key := this.currentLayerKey
- if (GetKeyState(key, "P")) {
- this.NotifyHold("Hold", key)
- startTime := A_TickCount
- KeyWait(key)
- elapsedTime := A_TickCount - startTime
- if (elapsedTime >= 250) {
- this.Notify("Released")
- }
- }
- }
- static Release() {
- try {
- Send("{F12 Up}{F13 Up}{F14 Up}")
- Send("{LControl Up}{RControl Up}")
- Send("{LShift Up}{RShift Up}")
- Send("{LWin Up}{RWin Up}")
- Send("{LAlt Up}{RAlt Up}")
- }
- }
- }
- ;/////////////////////////
- Layer1(IsHold, Taps, State) {
- Layer.SetLayer("F14")
- switch {
- case IsHold:
- Layer.Hold()
- case Taps = 1:
- if (State = -1)
- Layer.Notify("Tap")
- Command.Run()
- case Taps = 2:
- Layer.Notify("TapHold")
- SoundBeep(500, 100)
- KeyWait("F14", "L")
- if (State = -1)
- Layer.Notify("TapHold")
- case Taps = 3:
- Command.SnippingTool()
- Layer.Notify("TripleTap")
- case Taps = 4:
- Command.RestartExplorer()
- Layer.Notify("QuadrupleTap")
- Beep.RunSound()
- }
- }
- Layer2(IsHold, Taps, State) {
- Layer.SetLayer("F13")
- switch {
- case IsHold:
- Layer.Hold()
- case Taps = 1:
- if (State = -1)
- Layer.Notify("Tap")
- Command.Run()
- case Taps = 2:
- Layer.Notify("TapHold")
- SoundBeep(500, 100)
- KeyWait("F13", "L")
- if (State = -1)
- Layer.Notify("TapHold")
- case Taps = 3:
- Command.SnippingTool()
- Layer.Notify("TripleTap")
- case Taps = 4:
- Command.RestartExplorer()
- Layer.Notify("QuadrupleTap")
- Beep.RunSound()
- }
- }
- Layer3(IsHold, Taps, State) {
- Layer.SetLayer("F12")
- switch {
- case IsHold:
- switch {
- case (Taps = 2 && State = 0):
- Layer.Notify("TapHold")
- WindowState.UnMinimize()
- case (Taps = 3 && State = 0):
- Layer.Notify("TapTapHold")
- WindowState.UnMinimize()
- }
- Layer.Hold()
- case Taps = 1:
- if (State = -1)
- WindowState.Minimize()
- Layer.Notify("Tap")
- case Taps = 2:
- Layer.Notify('DoubleTap')
- case Taps = 3:
- Layer.Notify('TripleTap')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement