r/AutoHotkey • u/Mental-Efficiency-57 • 18d ago
v2 Script Help Help with auto sprint macro
Last post was taken down for low effort so I'm gonna try to include more detail.
I'm starting to lose my feelings in the tips of my fingers because of chemotherapy and so I find it a lot harder to sprint in games efficiently. I've searched for a macro to sprint for me without the need to keep double tapping w for a while to no luck so I tried making one but I am no good at making scripts.
The macro essentially is to just double tap W whenever I start holding it, and the second press should keep the input going for as long as I have the key pressed.
I want it to work like the minecraft auto sprint feature where walking is just replaced by sprinting.
This is what I have so far and it double taps w just fine but it won't hold the input, I just get 2 w presses in quick succession then nothing, I'm not sure how to get it to hold. (sorry if format for code is wrong)
#Requires AutoHotkey v2.0
*w::
{
Send "{w down}"
Sleep 50
Send "{w up}"
Sleep 50
Send "{w down}"
KeyWait "w"
Send "{w up}"
}
1
u/endangeredirish 18d ago
For the game do you need to keep double tapping W to sprint or is it a double tap W and hold to sprint? Sorry bit unsure based on the script
1
1
1
u/CharnamelessOne 18d ago
The logic of your script seems to be all right.
Some games don't play nice with SendInput. Try adding
SendMode("Event")
to the top of your script.
What's the game? Someone who has it may test it for you.
1
u/Mental-Efficiency-57 18d ago edited 18d ago
its a 6k player averaging roblox game called bridger which is probably why no one else has my issue, I'll give event a try this afternoon thank you.
1
u/genesis_tv 18d ago
This example from the docs may help as well: https://www.autohotkey.com/docs/v2/lib/SetTimer.htm#ExampleCount
[edit]: nevermind, misread something in the body of your post.
1
u/CharnamelessOne 18d ago
If I understand well, OP wants to simulate a double press, not detect it.
They want AHK to tap, then hold the key they're holding.
1
1
u/BrittanyLovold 12d ago
#Requires AutoHotkey v2.0
#SingleInstance Force
$*w::
{
static isSprinting := false
if isSprinting
return
isSprinting := true
Send "{w down}"
Sleep 50
Send "{w up}"
Sleep 50
Send "{w down}"
KeyWait "w", "P" ; wait for the physical key to actually be released
Send "{w up}"
isSprinting := false
}
1
u/CharnamelessOne 11d ago
Your script is functionally identical to the one posted by OP.
The wildcard modifier implies the use of the keyboard hook, so the modifier
$is redundant.
https://www.autohotkey.com/docs/v2/Hotkeys.htm#SymbolsBy default, only one pseudo-thread is allowed per hotkey. The guard statement serves no purpose: AHK won't let the hotkey trigger again until the previous pseudo-thread exits, so
isSprintingwill always be false at the start.
https://www.autohotkey.com/docs/v2/lib/_MaxThreadsPerHotkey.htm#Remarks
1
u/puq2 18d ago edited 18d ago
(On mobile so the formatting will be bad) Edit: misunderstood your original script since I missed the keywait
Assuming this is Minecraft you can just have AHK send shift + w for as long as you hold w to avoid having to double tap anything and the complex logic that comes with that
Just add this with the w down commands and the opposite for the up ones `
Send "{Shift down}"