Page 1 of 1

Code to press R every 5 seconds

Posted: 01 May 2021, 17:15
by Alebzeb
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 :)

Re: Code to press R every 5 seconds

Posted: 01 May 2021, 19:45
by mikeyww

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

Re: Code to press R every 5 seconds

Posted: 12 May 2021, 17:22
by JonesJ
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

Re: Code to press R every 5 seconds

Posted: 12 May 2021, 17:33
by mikeyww
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/