Multiple commands with different delays in one hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xerislight
Posts: 2
Joined: 20 Oct 2021, 20:26

Multiple commands with different delays in one hotkey

20 Oct 2021, 20:32

I'm trying to create a hotkey for a game that will press 2 different keys on different timers... Here's the script I have for one hotkey:

Code: Select all

#MaxThreadsPerHotkey 2
Numpad1::
   toggle:=!toggle
   While toggle{
	SetKeyDelay, 10
	Send {3}
	Sleep 20500
   }
Return
[Mod edit: [code][/code] tags added.]


So basically, every 20500 ms, AHK will hit the 3 hotkey. I want to add the 2 hotkey on a different timer, something like... 300 instead of 20500.

So basically I want to be able to hit Numpad1, and every 300ms, hit hotkey 2, and every 20500ms hit hotkey 3. Is that doable? I'm not sure how to construct that! Any help appreciated.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Multiple commands with different delays in one hotkey

20 Oct 2021, 21:22

You referred to three hotkeys, but your script has only one, so your intent is not clear.

Yes, you can use SetTimer. Example

Your hotkey can start two timers-- two different SetTimer commands. Each timer will have its own subroutine.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Multiple commands with different delays in one hotkey

20 Oct 2021, 22:10

Code: Select all

#MaxThreadsPerHotkey 2
You should up that or else you may get stuck in your while loop.

perhaps 15 **Arbitrary number**
xerislight
Posts: 2
Joined: 20 Oct 2021, 20:26

Re: Multiple commands with different delays in one hotkey

21 Oct 2021, 01:44

mikeyww wrote:
20 Oct 2021, 21:22
You referred to three hotkeys, but your script has only one, so your intent is not clear.

Yes, you can use SetTimer. Example

Your hotkey can start two timers-- two different SetTimer commands. Each timer will have its own subroutine.
Yes, this is my issue. My script has one hotkey... I want to figure out how to add a second key on a different timer, using the same macro. In the example I posted, the macro is pressing "3" every 20.5 seconds (roughly). I want the macro press "3" every 20,500 seconds, but also press "1" every 5 seconds. I'm not sure how to make it do that.

I read the "SetTimer" page you linked, but the examples there, for example:

Code: Select all

#Persistent
SetTimer, CloseMailWarnings, 250
return

CloseMailWarnings:
WinClose, Microsoft Outlook, A timeout occured while communicating
WinClose, Microsoft Outlook, A connection to the server could not be established
return
[Mod edit: [code][/code] tags added.]

This also seems to only be doing 1 thing.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Multiple commands with different delays in one hotkey

21 Oct 2021, 06:28

Code: Select all

Numpad1::
If on := !on {
 SoundBeep, 1500
 Gosub, 1
 Gosub, 3
 SetTimer, 1, 5000
 SetTimer, 3, 20500
 Return
}
SetTimer, 1, Off
SetTimer, 3, Off
SoundBeep, 1000
Return

1:
3:
Send %A_ThisLabel%
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 263 guests