Code to press R every 5 seconds

Ask gaming related questions (AHK v1.1 and older)
Alebzeb
Posts: 1
Joined: 01 May 2021, 17:11

Code to press R every 5 seconds

Post by Alebzeb » 01 May 2021, 17:15

I need a program to press R on my keyboard every 5 seconds, over and over. I'd like to switch it on and off with F2. Can someone give me the code for this I would be very grateful :)

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Code to press R every 5 seconds

Post by mikeyww » 01 May 2021, 19:45

Code: Select all

F2::
+F2::
If press := !press {
 Gosub, PressR
 SetTimer, PressR, 5000
} Else SetTimer, PressR, Off
SoundBeep, 1000 + 500 * press
Return
PressR:
Send R
Return

JonesJ
Posts: 2
Joined: 12 May 2021, 16:47

Re: Code to press R every 5 seconds

Post by JonesJ » 12 May 2021, 17:22

mikeyww wrote:
01 May 2021, 19:45

Code: Select all

F2::
+F2::
If press := !press {
 Gosub, PressR
 SetTimer, PressR, 5000
} Else SetTimer, PressR, Off
SoundBeep, 1000 + 500 * press
Return
PressR:
Send R
Return
how would i do this for A being the key to be entered on a game continuously? i tried this code with A instead of R and it worked but not on my game

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Code to press R every 5 seconds

Post by mikeyww » 12 May 2021, 17:33

If it works in Notepad but not in your game, then the issue might be how your game is responding to the script. You could have a look at the tips for games.

https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

Post Reply

Return to “Gaming Help (v1)”