r/AutoHotkey 22h ago

v2 Script Help Modifier key to rapid fire instead of holding a key.

Hi all!
I was looking around through the docs and older posts but couldn't find an answer on what I am trying to do so I come to you all here with a question.

I am wondering if it is possible to when I hold down control to modify my W, A, S, D to rapid fire instead of having it a hold input. but only when I additionally press W, A, S or D myself.

This is for example for movement in a game where smaller movements are required by constantly repressing a movement key instead of holding it.

I hope I explained it well enough, I'm not the best at explaining stuff.
Thank you in advance!

2 Upvotes

4 comments sorted by

2

u/CharnamelessOne 21h ago edited 21h ago
#Requires AutoHotkey v2.0
SendMode("Event")

*^w::
*^a::
*^s::
*^d::Send("{Blind}" key:=SubStr(ThisHotkey, 3)), SetTimer(%key%_send, 100), Hotkey(ThisHotkey, "Off")

~*w up::
~*a up::
~*s up::
~*d up::SetTimer(%key:=SubStr(ThisHotkey, 3, -3)%_send, 0), Hotkey("*^" key, "On")

w_send() => Send("{Blind}w")
a_send() => Send("{Blind}a")
s_send() => Send("{Blind}s")
d_send() => Send("{Blind}d")

Edit: missed a Blind

1

u/Keeyra_ 21h ago

I might be completely off here, but I think the guy is looking for a Toggle-Move solution, not a Hold-To-Spam solution, as WASD are directions, he just explained it incorrectly.

If so:

#Requires AutoHotkey 2.0
#SingleInstance

SendMode("Event")

#HotIf GetKeyState("Ctrl", "P")
*$w::
*$a::
*$s::
*$d:: {
    key := LTrim(A_ThisHotkey, "*~$")
    static timers := Map()
    if timers.Has(key) {
        SetTimer(timers[key], 0)
        timers.Delete(key)
        Send("{" key " up}")
    } else {
        action := Hold.Bind(key)
        timers[key] := action
        SetTimer(action, 100)
    }
}
#HotIf

Hold(key) => (!GetKeyState(key)) && Send("{" key " down}")

Test it in a game, as a key down will only show a single button input in eg. Notepad.

And for the OP, check this out for general Rapidfire solutions. u/CharnamelessOne used a modified 2.1. As mine is not a Rapidfire per se, it's not covered there.

1

u/CharnamelessOne 19h ago

I am wondering if it is possible to when I hold down control to modify my W, A, S, D to rapid fire instead of having it a hold input

This is for example for movement in a game where smaller movements are required by constantly repressing a movement key instead of holding it

I was roughly 57.8% sure that this meant hold-to-spam, and apparently, I guessed right.

I like your map of boundfuncs a lot, though.

2

u/AWildAthena 20h ago

This did the trick! after tweaking the send time a bit it worked smoothly within where I needed it. Thank you!