Compare commits

...

4 Commits

  1. 85
      lib/HoldRepeat.ahk
  2. 5
      lib/Prelude.ahk
  3. 8
      scripts/AutorunAutoclick.ahk
  4. 8
      scripts/Deep Rock Galactic.ahk
  5. 16
      scripts/Minecraft Bedrock Edition.ahk
  6. 4
      scripts/Stardew Valley.ahk
  7. 21
      scripts/Subnautica.ahk
  8. 12
      scripts/Valheim.ahk

85
lib/HoldRepeat.ahk

@ -1,87 +1,92 @@
; Functions for holding and repeating keys
;
; Private Functions
; Private Methods
;
_HoldRepeat_LoopState := Map()
_HoldRepeat_IsActive := Map()
_HoldRepeat_Handler(Mode, TargetKey, CancelKeys:=[], HoldKey?, BlindMode:="{Blind}") {
_HoldRepeat_Handler(IsHold, TargetKey, CancelKeys:=[], HoldKey:="") {
global _HoldRepeat_IsActive
global HoldRepeat_BlindMode
global HoldRepeat_TimerPeriod
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)
if (CancelKeys.Length == 0 AND !HoldKey) {
if IsHold {
CancelKeys:=[TargetKey]
} else {
HoldKey:=TargetKey
}
} else if (Mode == "Repeat") {
_HoldRepeat_LoopState[TargetKey] := true
} else {
return
}
SetTimer _HoldRepeat_Loop.Bind(TargetKey,CancelKeys,HoldKey?,BlindMode), 50
if IsHold {
Send HoldRepeat_BlindMode "{" TargetKey " down}"
}
SetTimer _HoldRepeat_Loop.Bind(IsHold, TargetKey, CancelKeys, HoldKey), HoldRepeat_TimerPeriod
}
_HoldRepeat_Loop(TargetKey, CancelKeys, HoldKey?, BlindMode:="{Blind}") {
_HoldRepeat_Loop(IsHold, TargetKey, CancelKeys, HoldKey) {
global _HoldRepeat_LoopState
global _HoldRepeat_IsActive
global HoldRepeat_BlindMode
endLoop := false
for index,key in CancelKeys {
if GetKeyState(key,"P") {
Send BlindMode "{" TargetKey " up}"
endLoop := true
break
}
}
if IsSet(HoldKey) {
if !GetKeyState(HoldKey,"P") {
Send BlindMode "{" TargetKey " up}"
endLoop := true
}
} else {
if GetKeyState(TargetKey,"P") {
endLoop := true
}
if (HoldKey AND !GetKeyState(HoldKey,"P")) {
endLoop := true
}
if endLoop {
SetTimer , 0
if (IsHold AND !GetKeyState(TargetKey,"P")) {
Send HoldRepeat_BlindMode "{" TargetKey " up}"
}
_HoldRepeat_IsActive[TargetKey] := false
return
}
if _HoldRepeat_LoopState.Has(TargetKey) {
updown := (_HoldRepeat_LoopState[TargetKey] ? "up" : "down")
Send BlindMode "{" TargetKey " " updown "}"
_HoldRepeat_LoopState[TargetKey] := !_HoldRepeat_LoopState[TargetKey]
if !IsHold {
Send HoldRepeat_BlindMode "{" TargetKey "}"
}
}
;
; Public Functions
; Public Methods
;
Hold := _HoldRepeat_Handler.Bind("Hold")
Repeat := _HoldRepeat_Handler.Bind("Repeat")
; Make BlindMode a public variable so it doesn't have to be passed as an input to every function
; plus it's highly unlikely we will want different modes in different hotkeys for the same script
HoldRepeat_BlindMode := "{Blind}"
HoldRepeat_TimerPeriod := 100
Hold := _HoldRepeat_Handler.Bind(true)
Repeat := _HoldRepeat_Handler.Bind(false)
; Sets key to hold if single tap, or repeat if double tap
HoldOrRepeat(TargetKey, CancelKeys?, BlindMode:="{Blind}") {
Send BlindMode "{" TargetKey " down}"
HoldOrRepeat(TargetKey, CancelKeys:=[]) {
global HoldRepeat_BlindMode
Send HoldRepeat_BlindMode "{" TargetKey " down}"
if KeyWait(TargetKey, "D T0.2") {
mode := "Repeat"
isHold := false
} else {
mode := "Hold"
isHold := true
}
_HoldRepeat_Handler(mode, TargetKey, CancelKeys,, BlindMode)
}
; Press Target button extremely rapidly while Hold button is held down
Turbo(TargetKey, HoldKey:=TargetKey,BlindMode:="{Blind}") {
While GetKeyState(HoldKey,"P") {
Send BlindMode "{" TargetKey "}"
if (CancelKeys.Length == 0) {
CancelKeys := [TargetKey]
}
_HoldRepeat_Handler(isHold, TargetKey, CancelKeys)
}

5
lib/Prelude.ahk

@ -23,5 +23,8 @@ A_MenuMaskKey := "vkFF"
#SingleInstance force
; Send Mode
SendMode "Event"
SendMode "Input"
SetKeyDelay -1
; Increase base number of max threads
#MaxThreads 20

8
scripts/AutorunAutoclick.ahk

@ -19,7 +19,7 @@
*!Space UP::HoldOrRepeat("Space")
; Autorun
*!w UP::Hold("w",["s"])
*!s UP::Hold("s",["w"])
*!a UP::Hold("a",["d","w","s"])
*!d UP::Hold("d",["a","w","s"])
*!w UP::Hold("w",["w","s"])
*!s UP::Hold("s",["w","s"])
*!a UP::Hold("a",["a","d","w","s"])
*!d UP::Hold("d",["d","a","w","s"])

8
scripts/Deep Rock Galactic.ahk

@ -54,16 +54,13 @@ RemoveTooltip() {
; Do full auto when caps lock is on for enabled weapons
#HotIf (GetKeyState("CapsLock","T") and FullAutoEnabled[EquipState])
*LButton::Repeat("LButton",,"LButton")
*LButton::Repeat("LButton")
;
; Distruptive macros
;
#HotIf FullAutoEnabled[5]
; Hold space rapidly jumps
*Space::Turbo("Space")
; Hold f to rapidly deposit
*f::{
While GetKeyState("f","P") {
@ -76,14 +73,13 @@ RemoveTooltip() {
}
}
;
; Non-disruptive macros
;
#HotIf
; Alt + E holds E
*!e UP::Hold("e",["w","a","s","d","Space","LButton","RButton"])
*!e UP::Hold("e",["e","w","a","s","d","Space","LButton","RButton"])
; Press shift to sprint, only toggles on
*LShift::{

16
scripts/Minecraft Bedrock Edition.ahk

@ -40,20 +40,20 @@ return
; Hold/Autoclick mouse buttons
; Holds if single click, autoclicks if double click
vkFF & LButton UP::HoldOrRepeat("LButton",["RButton","MButton"])
vkFF & RButton UP::HoldOrRepeat("RButton",["LButton","MButton"])
vkFF & LButton UP::HoldOrRepeat("LButton",["LButton","RButton","MButton"])
vkFF & RButton UP::HoldOrRepeat("RButton",["RButton","LButton","MButton"])
; Autorun
vkFF & w UP::Hold("w",["s"])
vkFF & s UP::Hold("s",["w"])
vkFF & a UP::Hold("a",["d","w","s"])
vkFF & d UP::Hold("d",["a","w","s"])
vkFF & w UP::Hold("w",["w","s"])
vkFF & s UP::Hold("s",["w","s"])
vkFF & a UP::Hold("a",["a","d","w","s"])
vkFF & d UP::Hold("d",["d","a","w","s"])
; Hold crouch
vkFF & Shift UP::Hold("Shift",["Ctrl"])
vkFF & Shift UP::Hold("Shift",["Shift","Ctrl"])
; Autojump/auto-ascend
vkFF & Space UP::Hold("Space",["Shift"])
vkFF & Space UP::Hold("Space",["Space","Shift"])
; Mouse button 4: auto-takeoff
; Macro assumes you have your fireworks in the first hotbar slot

4
scripts/Stardew Valley.ahk

@ -26,5 +26,5 @@ WrapperWindow:="Stardew Valley 1.6.8 - running SMAPI"
}
; Alt to hold or repeat mouse buttons
*!LButton UP::HoldOrRepeat("LButton",["RButton","MButton"])
*!RButton UP::HoldOrRepeat("RButton",["LButton","MButton"])
*!LButton UP::HoldOrRepeat("LButton",["LButton","RButton","MButton"])
*!RButton UP::HoldOrRepeat("RButton",["RButton","LButton","MButton"])

21
scripts/Subnautica.ahk

@ -14,18 +14,21 @@ WrapperWindow:="Subnautica"
; Hotkeys
;
SendMode "Event"
HoldRepeat_TimerPeriod:=20
; Alt + direction: automove
*!w UP::Hold("w",["s"])
*!s UP::Hold("s",["w"])
*!a UP::Hold("a",["d","w","s"])
*!d UP::Hold("d",["a","w","s"])
*!Space UP::Hold("Space",["LShift"])
*!LShift Up::Hold("LShift",["Space"])
*!w UP::Hold("w",["w","s"])
*!s UP::Hold("s",["w","s"])
*!a UP::Hold("a",["a","d","w","s"])
*!d UP::Hold("d",["d","a","w","s"])
*!Space UP::Hold("Space",["Space","LShift"])
*!LShift Up::Hold("LShift",["LShift","Space"])
; Alt + mouse key: hold key
*!LButton UP::Hold("LButton",["RButton","MButton"])
*!RButton UP::Hold("RButton",["LButton","MButton"])
*!LButton UP::Hold("LButton",["LButton","RButton","MButton"])
*!RButton UP::Hold("RButton",["RButton","LButton","MButton"])
; Turbo click to break rocks when caps lock on
#HotIf GetKeyState("CapsLock","T")
*LButton::Turbo("LButton")
*LButton::Repeat("LButton",,"LButton")

12
scripts/Valheim.ahk

@ -15,13 +15,15 @@ WrapperWindow:="Valheim"
; Hotkeys
;
HoldRepeat_BlindMode:=""
; Hold E
*#e UP::Hold("e",["LButton", "RButton","q","r"],,false)
*#e UP::Hold("e",["e","LButton", "RButton","q","r"])
; Autorun
*#w UP::Hold("w",["s"],,false)
*#Shift UP::Hold("Shift",["Ctrl"],["w"],false)
*#w UP::Hold("w",["w","s"])
*#Shift UP::Hold("Shift",["Shift","Ctrl"],["w"])
; Autoclick
*#LButton UP::HoldOrRepeat("LButton",["RButton","MButton"],false)
*#RButton UP::HoldOrRepeat("RButton",["LButton","MButton"],false)
*#LButton UP::HoldOrRepeat("LButton",["LButton","RButton","MButton"])
*#RButton UP::HoldOrRepeat("RButton",["RButton","LButton","MButton"])
Loading…
Cancel
Save