Help with auto sprint

Ask gaming related questions (AHK v1.1 and older)
Hattifnatt
Posts: 2
Joined: 23 Oct 2021, 12:13

Help with auto sprint

23 Oct 2021, 12:21

Hello,

Playing Borderlands 2, I made some always run script so everytime when I press W (forward) it also sends Shift so it toggles sprinting. It looks like this:

Code: Select all

#IfWinActive Borderlands 2
w:: 
	Send {Shift down}{w down}
	KeyWait, w
	Send {Shift up}{w up}
Return
#IfWinActive
It seems to work pretty well, but if I fire (left mouse button) or ADS (right mouse button) while W is being pressed, the sprint stops. This is because of the game, sprinting is toggled with Shift and is cancelled if you fire or ADS.

What I want is that after I fire of ADS, sprinting will continue without me having to release the W key and press it again. Is that possible? I couldn't make it work, please help :)
Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help with auto sprint

23 Oct 2021, 13:04

Hallo,
perhaps:

Code: Select all

#If WinActive("Borderlands 2") And !GetKeyState("LButton","P") And !GetKeyState("RButton","P")
*w::Send, {Shift down}{w down}
*w Up::Send, {Shift up}{w up}
#If WinActive("Borderlands 2") And GetKeyState("w","P")
*LButton::Send, {Shift Up}{LButton Down}
*LButton Up::Send, {LButton Up}{Shift down}
*RButton::Send, {Shift Up}{RButton Down}
*RButton Up::Send, {RButton Up}{Shift down}
#If
Hattifnatt
Posts: 2
Joined: 23 Oct 2021, 12:13

Re: Help with auto sprint

23 Oct 2021, 20:49

Thank you a lot for trying to help!

But it doesn't work. It behaves the same as before, it's sprinting ok, but when I fire or use ADS it stops and I have to press W again. If i press it really fast afterwards, it will just move without sprinting, so I have to press it twice which is a bit annoying, same as before. Also, with the script above, sometimes I will get stuck on firing continuously although the mouse button is released, so I switched back to the simple version.

Ideally, I would guess I would wish for something like detect when one of my mouse buttons is released, then send Shift (maybe after a very short delay) so I can start sprinting again. But I don't know how to do it.
Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help with auto sprint

24 Oct 2021, 03:33

Borderlands 2 is not installed here, so I tested the logical key states in a Notepad window. Are there any differences?
Please use in the description instead of sprinting and ADS key states e.g. W=down + Shift=down.

Code: Select all

SetTimer,State,200,Keys:="w Shift LButton RButton"
State: ;Keys separated with space or tab
For all,Key in StrSplit(Keys,[A_Space,A_Tab])
	Text.=Trim(Key)>""?"`n" Key "`t" (GetKeyState(Key)?"down":"up"):
MouseGetPos, MX, MY ;separated from another ToolTip
ToolTip,% SubStr(Text,2),MX+16,MY+32,4,Text:=""
Return

#If (WinActive("Borderlands 2") Or WinActive("ahk_class Notepad"))
	And !GetKeyState("LButton","P") And !GetKeyState("RButton","P")
*w::Send, {Shift down}{w down}
*w Up::Send, {Shift up}{w up}
#If (WinActive("Borderlands 2") Or WinActive("ahk_class Notepad")) 
	And GetKeyState("w","P")
*LButton::Send, {Shift Up}{LButton Down}
*LButton Up::Send, {LButton Up}{Shift down}
*RButton::Send, {Shift Up}{RButton Down}
*RButton Up::Send, {RButton Up}{Shift down}
#If

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 47 guests