diff --git a/lib/HoldRepeat.ahk b/lib/HoldRepeat.ahk index f0e39a1..c7dcf15 100644 --- a/lib/HoldRepeat.ahk +++ b/lib/HoldRepeat.ahk @@ -1,97 +1,87 @@ -; ; Functions for holding and repeating keys + +; +; Internal Functions ; -_HoldRepeat_TurboOn := Map() +_HoldRepeat_LoopState := Map() +_HoldRepeat_IsActive := Map() -_GetPrefix(SendBlind) { - if (SendBlind) { - return "{Blind}" +_HoldRepeat_Handler(Mode, TargetKey, CancelKeys:=[], HoldKey?, BlindMode:="{Blind}") { + global _HoldRepeat_IsActive + if (_HoldRepeat_IsActive.Has(TargetKey) AND _HoldRepeat_IsActive[TargetKey]) { + return + } + _HoldRepeat_IsActive[TargetKey] := true + + Send BlindMode "{" TargetKey " down}" + if (Mode == "Hold") { + if _HoldRepeat_LoopState.Has(TargetKey) { + _HoldRepeat_LoopState.Delete(TargetKey) + } + } else if (Mode == "Repeat") { + _HoldRepeat_LoopState[TargetKey] := true } else { - return "" + return } + SetTimer _HoldRepeat_Loop.Bind(TargetKey,CancelKeys,HoldKey?,BlindMode), 50 } -Hold(Primary, Secondary:=[], Tertiary:=[], SendBlind:=true) { - Prefix := _GetPrefix(SendBlind) - Send Prefix "{" Primary " down}" - SetTimer HoldLoop.Bind(Primary,Secondary,Tertiary,Prefix), 50 -} +_HoldRepeat_Loop(TargetKey, CancelKeys, HoldKey?, BlindMode:="{Blind}") { + global _HoldRepeat_LoopState + global _HoldRepeat_IsActive -HoldLoop(Primary, Secondary, Tertiary, Prefix) { - if GetKeyState(Primary,"P") { - SetTimer , 0 - return - } - for index,key in Secondary { + endLoop := false + for index,key in CancelKeys { if GetKeyState(key,"P") { - Send Prefix "{" Primary " up}" - SetTimer , 0 - return + Send BlindMode "{" TargetKey " up}" + endLoop := true } } - keyHeld:=!Tertiary.Length - for index,key in Tertiary { - if GetKeyState(key) { - keyHeld:=1 - break + if IsSet(HoldKey) { + if !GetKeyState(HoldKey,"P") { + Send BlindMode "{" TargetKey " up}" + endLoop := true + } + } else { + if GetKeyState(TargetKey,"P") { + endLoop := true } } - if (!keyHeld) { - Send Prefix "{" Primary " up}" + if endLoop { SetTimer , 0 + _HoldRepeat_IsActive[TargetKey] := false return } -} -Repeat(Primary, Secondary:=[], SendBlind:=true) { - Prefix := _GetPrefix(SendBlind) - Send Prefix "{" Primary " up}" - Sleep 100 - RepeatVar := 0 - Loop { - if GetKeyState(Primary,"P") { - return - } - for index,key in Secondary { - if GetKeyState(key,"P") { - return - } - } - if (RepeatVar == 0) { - Send Prefix "{" Primary " down}" - RepeatVar := 1 - } else { - Send Prefix "{" Primary " up}" - RepeatVar := 0 - } - Sleep 50 + if _HoldRepeat_LoopState.Has(TargetKey) { + updown := (_HoldRepeat_LoopState[TargetKey] ? "up" : "down") + Send BlindMode "{" TargetKey " " updown "}" + _HoldRepeat_LoopState[TargetKey] := !_HoldRepeat_LoopState[TargetKey] } } +; +; Internal Functions +; + +Hold := _HoldRepeat_Handler.Bind("Hold") +Repeat := _HoldRepeat_Handler.Bind("Repeat") + ; Sets key to hold if single tap, or repeat if double tap -HoldOrRepeat(Primary, Secondary:=[], SendBlind:=True) { - Send _GetPrefix(SendBlind) "{" Primary " down}" - if KeyWait(Primary, "D T0.2") { - Repeat(Primary,Secondary,SendBlind) +HoldOrRepeat(TargetKey, CancelKeys?, BlindMode:="{Blind}") { + Send BlindMode "{" TargetKey " down}" + if KeyWait(TargetKey, "D T0.2") { + mode := "Repeat" } else { - Hold(Primary,Secondary,,SendBlind) + mode := "Hold" } + _HoldRepeat_Handler(mode, TargetKey, CancelKeys,, BlindMode) } ; Press Target button extremely rapidly while Hold button is held down -Turbo(Target, Hold:=Target) { - global _HoldRepeat_TurboOn - If (_HoldRepeat_TurboOn.Has(Target "_" Hold) and _HoldRepeat_TurboOn[Target "_" Hold]) { - return - } else { - _HoldRepeat_TurboOn[Target "_" Hold]:=1 - While GetKeyState(Hold,"P") { - SendEvent "{Blind}{" Target " down}" - Sleep 10 - SendEvent "{Blind}{" Target " up}" - Sleep 10 - } - _HoldRepeat_TurboOn[Target "_" Hold]:=0 +Turbo(TargetKey, HoldKey:=TargetKey,BlindMode:="{Blind}") { + While GetKeyState(HoldKey,"P") { + Send BlindMode "{" TargetKey "}" } } \ No newline at end of file diff --git a/lib/Prelude.ahk b/lib/Prelude.ahk index 1154c7a..947b845 100644 --- a/lib/Prelude.ahk +++ b/lib/Prelude.ahk @@ -23,5 +23,5 @@ A_MenuMaskKey := "vkFF" #SingleInstance force ; Send Mode -SendMode "Input" +SendMode "Event" SetKeyDelay -1 \ No newline at end of file diff --git a/src/Deep Rock Galactic.ahk b/src/Deep Rock Galactic.ahk index 3284ced..cdedea2 100644 --- a/src/Deep Rock Galactic.ahk +++ b/src/Deep Rock Galactic.ahk @@ -19,10 +19,10 @@ ToggleFullAuto(Index) { global FullAutoEnabled FullAutoEnabled[Index] := !FullAutoEnabled[Index] EnabledDisabled := (FullAutoEnabled[Index] ? "enabled" : "disabled") - if (Index < 5) { - ToolTip "Full Auto " EnabledDisabled " for " Index, A_ScreenWidth // 2, A_ScreenHeight // 2 + if (Index == 5) { + ToolTip "Auto jump " EnabledDisabled, A_ScreenWidth // 2, A_ScreenHeight // 2 } else { - ToolTip "Extra macros " EnabledDisabled, A_ScreenWidth // 2, A_ScreenHeight // 2 + ToolTip "Full Auto " EnabledDisabled " for " Index, A_ScreenWidth // 2, A_ScreenHeight // 2 } SetTimer RemoveTooltip, -1000 } @@ -54,28 +54,26 @@ RemoveTooltip() { ; Do full auto when caps lock is on for enabled weapons #HotIf (GetKeyState("CapsLock","T") and FullAutoEnabled[EquipState]) -*LButton::Turbo("LButton") +*LButton::Repeat("LButton",,"LButton") + +; Hold space rapidly jumps +#HotIf FullAutoEnabled[5] +*Space::Turbo("Space") ; ; Other ; -#HotIf FullAutoEnabled[5] +#HotIf ; Alt + E holds E *!e UP::Hold("e",["w","a","s","d","Space","LButton","RButton"]) -; Alt + W holds W -*!w UP::Hold("w",["s"]) - ; Press shift to sprint, only toggles on *LShift::{ Send "{Blind}{LShift up}{LShift down}" KeyWait("LShift") } -*LShift UP::Hold("LShift",,["w"]) - -; Hold space rapidly jumps -*Space::Turbo("Space") +*LShift UP::Hold("LShift",,"w") ; Grenade animation canceling *MButton::Send "{Blind}{LCtrl down}{MButton down}"