Simple Toggle 'hold w'

Ask gaming related questions
TiredFingers
Posts: 3
Joined: 04 Jan 2024, 14:35

Simple Toggle 'hold w'

04 Jan 2024, 14:56

Hi, brand new to AHK and was wondering if someone could help me with/write a simple script that can toggle on 'holding down' the 'w' key until it is toggled off. I'd like the toggle to be ^!w (CTRL-ALT-W) unless having the toggle be the same as the held down key would cause problems, in which case ^!q would be just fine, whatever is easiest.

This is to create a basic auto-walk function in minecraft so I can give my middle finger a break from holding down w all the time. I found a few threads doing the same thing in AHK v1 forums but don't know how to translate them to v2.
TiredFingers
Posts: 3
Joined: 04 Jan 2024, 14:35

Re: Simple Toggle 'hold w'

04 Jan 2024, 17:19

Closest thing I've found so far:

Code: Select all

F1:: {
    static toggled := false
    static SendKey := Send.Bind('{w}')  ; alternatively: static SendKey := () => Send('{w}')
    if toggled := !toggled
        SetTimer(SendKey, 20)
    else
        SetTimer(SendKey, 0)
}
But this sends the input "w" over and over again, as if repeatedly pressing the button. I need it to 'hold down' the button.
TiredFingers
Posts: 3
Joined: 04 Jan 2024, 14:35

Re: Simple Toggle 'hold w'

04 Jan 2024, 19:46

Alright, got it (sort of) working. Toggling it on and off does make it stop typing "w" but my character does not stop walking (this is an auto-walker for minecraft) for a good amount of time. I'm not sure what the trigger to stop my character is, but I think it has something to do with hitting F1 then typing then jumping onto a higher block. Not sure how to fix this but it functions sufficiently for now!

Code: Select all

F1:: {
    static toggled := false
    static SendKey := () => Send('{w down}')
    if toggled := !toggled
        SetTimer(SendKey, 20)
    else
        SetTimer(SendKey, 0)
}
niCode
Posts: 335
Joined: 17 Oct 2022, 22:09

Re: Simple Toggle 'hold w'

04 Jan 2024, 20:33

Code: Select all

^!w:: {
    KeyWait('w')
    SendEvent('{w ' (GetKeyState('w') ? 'up' : 'down') '}')
}

Return to “Gaming Help (v2)”

Who is online

Users browsing this forum: No registered users and 12 guests