KJey Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Paradoxz1
Posts: 2
Joined: 11 May 2018, 14:19

KJey

Post by Paradoxz1 » 22 Jan 2021, 16:34

Hello! I need help, I have two scripts which hold down A and then another that holds down D when a button is toggled. I wanna combined these two so that the script holds down the A key for 38 seconds then it switches and holds down the D key and then switches again until I toggle the script. This is the script for a single button hold down (Press left arrow and it holds down A) can anyone help me with how I should combine these two scripts with sleep or timer in between to make them switch after 38 seconds.

Code: Select all

#Persistent
#MaxThreadsPerHotkey 2
toggle := False
Left UP::
toggle := !toggle

Loop {
    If (!toggle) {
    send,{a UP}
        break
    }
    send,{a DOWN}
sleep 10
}
Return
This is what I came up with so far with some help but the issue with the code underneath is that it doesn't actually hold down the keys when script is ran.

Code: Select all

A := true

Left Up::SetTimer, AD38, % (toggle := !toggle) ? 38000 : "Off"

AD38:
    if (toggle)
    {
        if (A = true)
        {
            SendInput, {D Up}
            SendInput, {A Down}
            A := false
        }
        else
        {
            SendInput, {A Up}
            SendInput, {D Down}
            A := true
        }
    }
    else
    {
        SendInput, {A Up}
        SendInput, {D Up}
        A := true
    }
return
So in conclusion Im trying to make a script that holds down the A key for 38 seconds then switches to the D key for 38 seconds and then again back to A key and so on for infinity until the toggle key is pressed again.[/Codebox]
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: KJey  Topic is solved

Post by mikeyww » 22 Jan 2021, 17:22

Code: Select all

#MaxThreadsPerHotkey 2
wait := 38000
F3::
go := !go
While go {
 Send {a down}
 Sleep, % go ? wait : 0
 Send {a up}
 Send % go ? "{d down}" :
 Sleep, % go ? wait : 0
 Send {d up}
}
Return
Paradoxz1
Posts: 2
Joined: 11 May 2018, 14:19

Re: KJey

Post by Paradoxz1 » 22 Jan 2021, 17:43

mikeyww wrote:
22 Jan 2021, 17:22

Code: Select all

#MaxThreadsPerHotkey 2
wait := 38000
F3::
go := !go
While go {
 Send {a down}
 Sleep, % go ? wait : 0
 Send {a up}
 Send % go ? "{d down}" :
 Sleep, % go ? wait : 0
 Send {d up}
}
Return
This does work thank you so much only one question, is it possible to add so when F7 is pressed again or any other key of your choosing to break the loop
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: KJey

Post by mikeyww » 22 Jan 2021, 20:08

F3 is a toggle, but it will not break a sleep. The following posts describe approaches for a breakable loop.

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=82813

https://www.autohotkey.com/boards/viewtopic.php?p=250076#p250076
Post Reply

Return to “Gaming Help (v1)”