Page 1 of 1

loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 04:39
by kroki
I am trying to make a script that will on right mouse button hold:

press f, then a, then d, then finally q. id like to put individual cooldowns on f,a,d, so when i click right mouse button before cooldown on these keys passes, it will only press q

heres what i come up with (without cooldowns)

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")
{
send f 
sleep 200
send a
sleep 200
send d
sleep 200
send q
sleep 10000
}
any help would be greatly appreciated :D

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 05:22
by Rohwedder
Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 05:28
by kroki
Rohwedder wrote:
17 Jan 2022, 05:22
Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?
cooldown meaning that it wont be pressed again if i rapidly click right mouse button, before the cooldown ends, for example 10 seconds for each key other than q

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 05:29
by kroki
Rohwedder wrote:
17 Jan 2022, 05:22
Hallo,
what does Cooldown of a key mean?
Should this key be held down for a certain period of time?
to prevent key being pressed again when i hold down right mouse button. for example 10 second period for all keys other than Q

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 08:29
by Rohwedder
Try:

Code: Select all

#If Cooldown
*f:: ;to prevent key being pressed again
*a:: ;when i hold down right mouse button
*d::Return
#IfWinActive ahk_class Diablo II
~RButton::
While, Cooldown := GetKeyState("RButton","P")
{
	send f
	sleep 200
	send a
	sleep 200
	send d
	sleep 200
	send q
	sleep 10000
}
Return

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 08:36
by kroki
hi, thanks for the reply. i dont understand how does this change anything though :(

ideally id want to press right mouse button, have ahk send keys: f,a,d with 200ms delay, then send q key. for f,a,d keys id like 10 seconds cooldown, so when i press right mouse button before 10 seconds run out, it only sends q

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 10:45
by Rohwedder
Then perhaps?:

Code: Select all

#If Cooldown ;so when i press right mouse button
RButton::send q ; before 10 seconds run out,
; it only sends q
#IfWinActive ahk_class Notepad ;ahk_class Diablo II
RButton::
SoundBeep, 4000, 20
Cooldown := True ;Cooldown starts
send f
sleep 200
send a
sleep 200
send d
sleep 200
send q
sleep 10000
Cooldown := False ;Cooldown ends
SoundBeep, 1000, 20
Return
The soundbeeps are only for testing to indicate the beginning and end of the Cooldown.

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 11:11
by kroki
unfortunately this doesnt work as i imagined.

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")
{
send f 		;start a 9 second cooldown
sleep 200
send a		;start a 10 second cooldown
sleep 200
send d		;start a 11 second cooldown
sleep 200
send q
}
any idea how to make it work like this? how to add 3 separe cooldowns to these key presses? and itd have to work on right mouse button hold, not just click

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 11:40
by kroki
ok ive tried different approach and it works, just one minor thing to do. how to make it loop on itself, without need to release to right click button?

Code: Select all

~RButton::
#IfWinActive ahk_class Diablo II

While, GetKeyState("RButton","P")

  {  
    if (!t1 || A_TickCount-t1 > 60000) { 
        t1 := A_TickCount 
        SendInput a
        Sleep 250
        SendInput s
        Sleep 250
        SendInput d
        Sleep 250
        SendInput q
    } else

    if (!t2 || A_TickCount-t2 > 9000) { 
        t2 := A_TickCount 
        SendInput a 
        Sleep 200
        SendInput d
        Sleep 200
        SendInput q
    } else

    if (!t3 || A_TickCount-t3 > 5000) { 
        t3 := A_TickCount 
   
        SendInput q

    } else


;GetKeyState, state, w,
;    if State = U
;    break

return 
}  

Re: loop-like script, but with individual cooldowns

Posted: 17 Jan 2022, 12:07
by Xtra
Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.

Re: loop-like script, but with individual cooldowns

Posted: 18 Jan 2022, 04:30
by kroki
Xtra wrote:
17 Jan 2022, 12:07
Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.
Works like a charm. Thank you everyone for replies :D

Re: loop-like script, but with individual cooldowns

Posted: 18 Jan 2022, 05:40
by kroki
Xtra wrote:
17 Jan 2022, 12:07
Give this a try:

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (A_Index = 1)
        {
            CDf := SendKey("f")
            CDa := SendKey("a")
            CDd := SendKey("d")   
        }
        else
        {
            if (A_TickCount - CDf >= 9000)
                CDf := SendKey("f")
            if (A_TickCount - CDa >= 10000)
                CDa := SendKey("a")
            if (A_TickCount - CDd >= 11000)
                CDd := SendKey("d")
        }
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}
You should be able to tweak the timing if needed.
one more thing, would it be possible to put a cooldown on the whole sequence? currently it runs whole thing each time i do a right click. id like to put another 10 second cd on the whole thing, during which time hodling right click would only send q

Re: loop-like script, but with individual cooldowns

Posted: 18 Jan 2022, 12:53
by Xtra
This will remember where the CD is at each time you right click.

Code: Select all

#IfWinActive ahk_class Diablo II
~RButton::
    While, GetKeyState("RButton","P") {
        if (!CDf || A_TickCount - CDf >= 9000)
            CDf := SendKey("f")
        if (!CDa || A_TickCount - CDa >= 10000)
            CDa := SendKey("a")
        if (!CDd || A_TickCount - CDd >= 11000)
            CDd := SendKey("d")
        SendKey("q", 0)
    }
return

SendKey(char, time := 200) {
    send, % char
    Sleep, time
    return A_TickCount
}

Re: loop-like script, but with individual cooldowns

Posted: 18 Jan 2022, 13:02
by kroki
works great, thanks!!