script that presses down a key with a cooldown

Ask gaming related questions (AHK v1.1 and older)
Veroxity
Posts: 3
Joined: 06 May 2021, 12:41

script that presses down a key with a cooldown

06 May 2021, 12:57

Hi i'm new to AutoHotkey i honestly don't know anything about it :crazy: 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.
User avatar
jasc2v8
Posts: 59
Joined: 10 Dec 2020, 12:24
Contact:

Re: script that presses down a key with a cooldown

06 May 2021, 13:06

What do you want to happen after the cool down, repeat? How do you want to terminate the loop, a different key? Anything else?
User avatar
Toonus
Posts: 3
Joined: 06 May 2021, 10:14

Re: script that presses down a key with a cooldown

06 May 2021, 13:45

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

Veroxity
Posts: 3
Joined: 06 May 2021, 12:41

Re: script that presses down a key with a cooldown

06 May 2021, 14:01

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.
User avatar
Toonus
Posts: 3
Joined: 06 May 2021, 10:14

Re: script that presses down a key with a cooldown

06 May 2021, 14:39

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.

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


Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 74 guests