script that presses down a key with a cooldown
script that presses down a key with a cooldown
Hi i'm new to AutoHotkey i honestly don't know anything about it But i was looking for a script that automatically presses R for 5 seconds and then have a 1 second cooldown after the cooldown it's going to loop, can someone please make that script?
Last edited by Veroxity on 06 May 2021, 13:22, edited 1 time in total.
Re: script that presses down a key with a cooldown
What do you want to happen after the cool down, repeat? How do you want to terminate the loop, a different key? Anything else?
Re: script that presses down a key with a cooldown
Somebody should check this because I'm new to all this as well. I dunno if it's really presses down the 'r' key for 5 secs, haha.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
This := 0 ; variable containing 0
Loop:
Loop
{
Send, % "{r down}"
Sleep, 50
This := This + 50 ; sleep command actually 'counts' the millisecs, this number will reflect the time
} until This = 5000 ; it adds up to 5000 ms so 5 secs
This := 0
Send, {r up}
sleep 1000 ; then 'cooldown' for 1000ms = 1 sec
Goto, Loop ; repeats loop
^e:: ; Ctrl + E terminates teh script, but only during sleep so if 'r' is not pressed down
ExitApp
Re: script that presses down a key with a cooldown
Well thanks it works but there is a problem i can't stop the script without using task manager
Edit: Neverming i just had to time it right.
Edit: Neverming i just had to time it right.
Re: script that presses down a key with a cooldown
I'm glad it worked
FYI, I modified the script in a way so you can see the accuracy of the time.
It probably depends on the CPU load, but during execution mine ranged from about 3,7 to 5,7 for the 5 secs.
FYI, I modified the script in a way so you can see the accuracy of the time.
It probably depends on the CPU load, but during execution mine ranged from about 3,7 to 5,7 for the 5 secs.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, ToolTip, Screen
This := 0
Loop:
StartTime := A_Tickcount
Loop
{
Send, % "{r down}"
Sleep, 50
This := This + 50
} until This = 5000
ToolTip, % "5 secs is actually (in ms): " A_Tickcount - StartTime, 0, 0, 1
This := 0
Send, {r up}
sleep 1000
ToolTip, % "Total Time elapsed in ms: " A_Tickcount - StartTime, 200, 0, 2
Goto, Loop
^e::
ExitApp
Who is online
Users browsing this forum: No registered users and 74 guests