Start 2 loops in parallel?

Ask gaming related questions (AHK v1.1 and older)
donjao
Posts: 2
Joined: 09 Dec 2015, 03:48

Start 2 loops in parallel?

17 Apr 2018, 03:46

Hello.

Essentially i'm trying to do this:

Code: Select all

~e::
    while GetKeyState("e","P")
    {
        Send {1 Down}
        Sleep 500
        Send {1 Up}
    }
    
    while GetKeyState("e","P")
    {
        Send {2 Down}
        Sleep 1000
        Send {2 Up}
    }
return
Note sleep difference. But, yes, only one loop is executed. In pseudo code it would be something like:

Code: Select all

when key "e" is pressed down
   start sending key 1
   wait 200 ms
   start sending key 2
return

when key "e" is released
   stop sending key 1
   stop sending key 2
return
Tried gosubs, but they are executed consequently, but i need concurrency. Any help much appreciated.

Thanks
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Start 2 loops in parallel?

17 Apr 2018, 04:41

Maybe this will work for you:

Code: Select all

~e::
    while GetKeyState("e","P")
    {
        if Mod(A_Index,2)
        {
            Send {1 Down}{2 Down}
            Sleep 500
            Send {1 Up}
        }
        else
        {
            Send {1 Down}
            Sleep 500
            Send {1 Up}{2 Up}
        }
    }
return
donjao
Posts: 2
Joined: 09 Dec 2015, 03:48

Re: Start 2 loops in parallel?

17 Apr 2018, 05:37

Yes! Thank you!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: doanmvu, Google [Bot] and 45 guests