Automatic script for pressing 2 different keys at different time intervals

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bullitt
Posts: 2
Joined: 06 Jun 2023, 07:06

Automatic script for pressing 2 different keys at different time intervals

Post by bullitt » 06 Jun 2023, 07:13

Hello!

A long time ago, a friendly dude from the AHK forums wrote a simple script for me that was perfect.

The purpose of the script is to use the F4 key to initiate/start the automatic rotation of pressing the 4 key (number, not keypad). There is a 22 second (22000ms) delay before the 4 key is being pressed again, and so it continues forever until pressing F4 again to stop the automatic rotation.

Please see the script here. It works great.

Code: Select all

F4:: ;On/Off with key F4
Send4active := !Send4active
If Send4active
	SetTimer Send4, 22000 ;spams the 4 key every 22000ms
Else
	SetTimer Send4, Off
Return
Send4: ;spams key 4
	Send, 4
Return
I would, however, like to add another key press on number 1 at every 13 second (13000ms) delay. So now there will be 2 different keys being pressed (4 and 1), starting at the same time, but with different intervals (4 at every 22 secs, and 1 at every 13 secs).

And then the script just rotates forever until F4 is being pressed again to deactivate the automatic rotation.

Can anyone help me with this?

Thank you!

[Mod edit: Wrong subforum: Moved topic to AHK v1 help, since this is not v2 code.]

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

Re: Automatic script for pressing 2 different keys at different time intervals

Post by mikeyww » 06 Jun 2023, 08:00

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v1.1.33

F4::
If Send4active := !Send4active {
 SetTimer Send4, 22000
 SetTimer Send1, 13000
} Else {
 SetTimer Send4, Off
 SetTimer Send1, Off
}
Return

Send4:
Send 4
Return

Send1:
Send 1
Return

bullitt
Posts: 2
Joined: 06 Jun 2023, 07:06

Re: Automatic script for pressing 2 different keys at different time intervals

Post by bullitt » 06 Jun 2023, 09:09

Absolutely fantastic, thank you very much Mikey!

Post Reply

Return to “Ask for Help (v1)”