diff --git a/lib/HoldRepeat.ahk b/lib/HoldRepeat.ahk index 818f641..7b5944c 100644 --- a/lib/HoldRepeat.ahk +++ b/lib/HoldRepeat.ahk @@ -2,32 +2,41 @@ ; Functions for holding and repeating keys ; -_TurboOn := [] +_TurboOn := Map() -Hold(Primary, Secondary) { - Send, {Blind}{%Primary% down} - if ( Secondary.Length() != 0 ) { - ThisLoop := Func("HoldLoop").bind(Primary,Secondary) - SetTimer, %ThisLoop%, 50 - } +Hold(Primary, Secondary:=[],Tertiary:=[]) { + Send "{Blind}{" Primary " down}" + SetTimer HoldLoop.Bind(Primary,Secondary,Tertiary), 50 } -HoldLoop(Primary, Secondary) { +HoldLoop(Primary, Secondary, Tertiary) { if GetKeyState(Primary,"P") { - SetTimer, , Delete + SetTimer , 0 return } for index,key in Secondary { if GetKeyState(key,"P") { - Send, {Blind}{%Primary% up} - SetTimer, , Delete + Send "{Blind}{" Primary " up}" + SetTimer , 0 return } } + keyHeld:=0 + for index,key in Tertiary { + if GetKeyState(key,"P") { + keyHeld:=1 + break + } + } + if (!keyHeld) { + Send "{Blind}{" Primary " up}" + SetTimer , 0 + return + } } Repeat(Primary, Secondary) { - Send, {Blind}{%Primary% up} + Send "{Blind}{" Primary " up}" Sleep 100 RepeatVar := 0 Loop { @@ -40,10 +49,10 @@ Repeat(Primary, Secondary) { } } if (RepeatVar == 1) { - Send, {Blind}{%Primary% down} + Send "{Blind}{" Primary " down}" RepeatVar := 0 } else { - Send, {Blind}{%Primary% up} + Send "{Blind}{" Primary " down}" RepeatVar := 1 } Sleep 100 @@ -52,9 +61,8 @@ Repeat(Primary, Secondary) { ; Sets key to hold if single tap, or repeat if double tap HoldOrRepeat(Primary, Secondary) { - Send, {Blind}{%Primary% down} - KeyWait, %Primary%, D, T0.2 - if (ErrorLevel = 0) { + Send "{Blind}{" Primary " down}" + if (KeyWait Primary, "D T0.2") { Repeat(Primary,Secondary) } else { Hold(Primary,Secondary) @@ -62,18 +70,22 @@ HoldOrRepeat(Primary, Secondary) { } ; Press Target button extremely rapidly while Hold button is held down -Turbo(Target,Hold) { +TurboOn(Target,Hold:=Target) { global _TurboOn - If (_TurboOn["%Target%_%Hold%"]) { + If (_TurboOn.Has(Target "_" Hold) and _TurboOn[Target "_" Hold]) { return } else { - _TurboOn["%Target%_%Hold%"]:=1 - While GetKeyState(Hold,"P") { - Send, {Blind}{%Target% down} + _TurboOn[Target "_" Hold]:=1 + While _TurboOn[Target "_" Hold] { + Send "{Blind}{" Target " down}" Sleep 10 - Send, {Blind}{%Target% up} + Send "{Blind}{" Target " up}" Sleep 10 } - _TurboOn["%Target%_%Hold%"]:=0 } +} + +TurboOff(Target,Hold:=Target) { + global _TurboOn + _TurboOn[Target "_" Hold]:=0 } \ No newline at end of file diff --git a/lib/Prelude.ahk b/lib/Prelude.ahk index 35d4923..29f48c6 100644 --- a/lib/Prelude.ahk +++ b/lib/Prelude.ahk @@ -5,21 +5,19 @@ ; Set default location and name convention for compiled scripts to use ;@Ahk2Exe-ExeName %A_MyDocuments%\AutoHotkey\bin\%A_ScriptName% -; Install hooks to make sure script can get physical state of keys instead of logical state. -#InstallKeybdHook -#InstallMouseHook - -#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. - -SendMode Input ; Recommended for new scripts due to its superior speed and reliability. - -SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. +; Require AutoHotKey v2 +#Requires AutoHotkey v2.0 +; Install hooks to make sure script can get physical state of keys instead of logical state. +InstallKeybdHook +InstallMouseHook ; All hotkeys are implemented through keyboard hook to avoid script activating itself. #UseHook +SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory. + ; MenuMaskKey is set to a virtual key that is defined by Windows as doing nothing -#MenuMaskKey vkFF +A_MenuMaskKey := "vkFF" ; If script is already running, just override it with the new version instead of asking #SingleInstance force \ No newline at end of file diff --git a/lib/Wrapper.ahk b/lib/Wrapper.ahk index 2f09be7..2519ba7 100644 --- a/lib/Wrapper.ahk +++ b/lib/Wrapper.ahk @@ -8,10 +8,9 @@ CheckWinExist(Window) { } } -Run %WrapperPath% +Run WrapperPath SetTitleMatchMode 3 -WinWait %WrapperWindow%,,600 +WinWait WrapperWindow,,600 ; Check if window exists once per second -WrapperFunc := Func("CheckWinExist").bind(WrapperWindow) -SetTimer, %WrapperFunc%, 1000 \ No newline at end of file +SetTimer CheckWinExist.Bind(WrapperWindow), 1000 \ No newline at end of file diff --git a/src/Deep Rock Galactic.ahk b/src/Deep Rock Galactic.ahk index 8c8f947..1cd6e75 100644 --- a/src/Deep Rock Galactic.ahk +++ b/src/Deep Rock Galactic.ahk @@ -1,18 +1,15 @@ -; Script can be directly run by or compiled into an .exe by the open-source software AutoHotkey -; https://www.autohotkey.com - -; +; ; Front Matter ; ; Include relevant libraries -#Include ../lib/Prelude.ahk -#Include ../lib/HoldRepeat.ahk +#Include "../lib/Prelude.ahk" +#Include "../lib/HoldRepeat.ahk" ; Make this a wrapper script WrapperPath:="steam://rungameid/548430" WrapperWindow:="Deep Rock Galactic " -#Include ../lib/Wrapper.ahk +#Include "../lib/Wrapper.ahk" ; Initialize variables FullAutoEnabled := [0,0,0,0] @@ -21,34 +18,43 @@ EquipState := 1 ToggleFullAuto(Index) { global FullAutoEnabled FullAutoEnabled[Index] := !FullAutoEnabled[Index] - EnabledDisabled := % (FullAutoEnabled[Index] ? "enabled" : "disabled") - ToolTip, Full Auto %EnabledDisabled% for %Index%, % A_ScreenWidth // 2, % A_ScreenHeight // 2 - SetTimer, RemoveTooltip, -1000 + EnabledDisabled := (FullAutoEnabled[Index] ? "enabled" : "disabled") + ToolTip "Full Auto " EnabledDisabled " for " Index, A_ScreenWidth // 2, A_ScreenHeight // 2 + SetTimer RemoveTooltip, -1000 } -RemoveTooltip: - ToolTip - return +RemoveTooltip() { + ToolTip +} ; ; Hotkeys ; ; Keep track of what is equipped -~*1:: EquipState := 1 -~*2:: EquipState := 2 -~*3:: EquipState := 3 -~*4:: EquipState := 4 +~*1:: global EquipState:=1 +~*2:: global EquipState:=2 +~*3:: global EquipState:=3 +~*4:: global EquipState:=4 ; FN toggles full auto for weapon N -~*F1::ToggleFullAuto(1) -~*F2::ToggleFullAuto(2) -~*F3::ToggleFullAuto(3) -~*F4::ToggleFullAuto(4) +*F1::ToggleFullAuto(1) +*F2::ToggleFullAuto(2) +*F3::ToggleFullAuto(3) +*F4::ToggleFullAuto(4) ; Alt + E holds E -*!e UP::Hold("e",["e","w","a","s","d","Space","LButton","RButton"]) +*!e UP::Hold("e",["w","a","s","d","Space","LButton","RButton"]) + +; Press shift to sprint, only toggles on +*LShift::Send "{Blind}{LShift down}" +*LShift UP::Hold("LShift",,["w"]) + +; Hold space rapidly jumps +*Space::TurboOn("Space") +*Space UP::TurboOff("Space") ; Do full auto when caps lock is on for enabled weapons -#If (GetKeyState("CapsLock","T") and FullAutoEnabled[EquipState]) -*LButton::Turbo("LButton","LButton") \ No newline at end of file +#HotIf (GetKeyState("CapsLock","T") and FullAutoEnabled[EquipState]) +*LButton::TurboOn("LButton") +*LButton UP::TurboOff("LButton") \ No newline at end of file