How to make this script automatically activate in every 20 second? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zerox
Posts: 79
Joined: 15 Apr 2021, 13:01

How to make this script automatically activate in every 20 second?

17 Apr 2024, 05:15

There is the code. So i want it to run for 5 second in every 20 second, thank you much for any help!

Code: Select all

F9:: Hotkey, *~$Space, Toggle
*Space::
Loop
{
GetKeyState,state,Space,P
if state = U
break

Sleep 10,00-5
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1
Send,{e}
Sleep -1

}
return

F10::Exitapp
User avatar
mikeyww
Posts: 27012
Joined: 09 Sep 2014, 18:38

Re: How to make this script automatically activate in every 20 second?

17 Apr 2024, 07:01

Code: Select all

#Requires AutoHotkey v1.1.33.11
runFor :=  5 ; Seconds
every  := 20 ; Seconds
SoundBeep 1500

Space Up::Reload
Space::
SetTimer Go, % 1000 * every
Gosub Go
KeyWait Space
Return

Go:
end := A_TickCount + 1000 * runFor
While (A_TickCount < end) {
 Send e
 Sleep 50
}
Return
Whenever the While loop iterates, the iteration executes to completion unless other control flow intervenes.
zerox
Posts: 79
Joined: 15 Apr 2021, 13:01

Re: How to make this script automatically activate in every 20 second?

17 Apr 2024, 16:41

mikeyww wrote:
17 Apr 2024, 07:01

Code: Select all

#Requires AutoHotkey v1.1.33.11
runFor :=  5 ; Seconds
every  := 20 ; Seconds
SoundBeep 1500

Space Up::Reload
Space::
SetTimer Go, % 1000 * every
Gosub Go
KeyWait Space
Return

Go:
end := A_TickCount + 1000 * runFor
While (A_TickCount < end) {
 Send e
 Sleep 50
}
Return
Whenever the While loop iterates, the iteration executes to completion unless other control flow intervenes.
Thank you but can i ask to do it toggle? Like if i press space, then activating script and run for 5 second in every 20 second. And may you do this with my code? I am using this script in a game where i have to take item with E, so the script speed is really important. This code upon too slow, i cant take anything with it. Thx!
User avatar
mikeyww
Posts: 27012
Joined: 09 Sep 2014, 18:38

Re: How to make this script automatically activate in every 20 second?  Topic is solved

18 Apr 2024, 06:26

An example is below. You can change the code as noted in the script.

Code: Select all

#Requires AutoHotkey v1.1.33.11
#MaxThreadsPerHotkey 2
runFor :=  5 ; Seconds
every  := 20 ; Seconds
SoundBeep 1500

Space::
If !on := !on {
 Reload
 Return
}
SetTimer Go, % 1000 * every
Go:
end := A_TickCount + 1000 * runFor
While (A_TickCount < end) {  ; Add the code to execute in your loop
 Send e
 Sleep 50
}
Return
User avatar
Chunjee
Posts: 1423
Joined: 18 Apr 2014, 19:05
Contact:

Re: How to make this script automatically activate in every 20 second?

19 Apr 2024, 13:33

zerox wrote:
17 Apr 2024, 05:15
How to make this script automatically activate in every 20 second?
A timer could be cool
User avatar
mikeyww
Posts: 27012
Joined: 09 Sep 2014, 18:38

Re: How to make this script automatically activate in every 20 second?

19 Apr 2024, 21:11

The posted script contains a timer. If needed, the subroutine can be called when the script runs.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Rohwedder and 354 guests