Missing Key in the Sequence Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Borndo
Posts: 4
Joined: 21 Sep 2022, 10:49

Missing Key in the Sequence

Post by Borndo » 21 Sep 2022, 11:06

Good day! I'm having a hard time with the script I made. What I want to happen is to spam buttons in a certain sequence with a 1 second delay in between each key. For example, the moment I press the F5 key, it will start a sequence that goes like "2 then 1 second delay, 3 then 1 second delay, 5 then one second delay, 4 then one second delay, 3 then one second delay'" and then it will start the sequence again after it hits the last key. However, instead of going "2-3-5-4-3" (the '-' representing the 1 second delay), the script I made goes like "2-3-5-4" and then it loops. My problem is that the last key shouldn't be 4 but 3, so how do I add 3 in the last part of the sequence?

The following is the script I made using Notepad:

Code: Select all

F5:: 
Send2active := !Send2active
If Send2active
	SetTimer Send2, 1000
Else
	SetTimer Send2, Off
Return
Send3active := !Send3active
If Send3active
	SetTimer Send3, 1000
Else
	SetTimer Send3, Off
Return
Send5active := !Send5active
If Send5active
	SetTimer Send5, 1000
Else
	SetTimer Send5, Off
Return
Send4active := !Send4active
If Send4active
	SetTimer Send4, 1000
Else
	SetTimer Send4, Off
Return
Send3active := !Send3active
If Send3active
	SetTimer Send3, 1000
Else
	SetTimer Send3, Off
Return
Send2: ;spams key 2
	Send, 2
Send3: ;spams key 3
	Send, 3
Send5: ;spams key 5
	Send, 5
Send4: ;spams key 4
	Send, 4
Return
[Mod edit: [code][/code] tags added.]

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Missing Key in the Sequence  Topic is solved

Post by Rohwedder » 21 Sep 2022, 15:35

Hallo,
your script starts only Timer Send2, which sends the complete sequence 2-3-5-4 once per second!

Code: Select all

F5:: 
Send2active := !Send2active
If Send2active
	SetTimer Send2, 1000
Else
	SetTimer Send2, Off
Return ; This return prevents the next lines from being executed
Send3active := !Send3active
If Send3active
	SetTimer Send3, 1000
Else
	SetTimer Send3, Off
Return
....
;Since Returns are missing, Send, 2 is immediately followed by Send, 3 ...
Send2: ;spams key 2
	Send, 2
;Return missing
Send3: ;spams key 3
	Send, 3
;Return missing
Send5: ;spams key 5
	Send, 5
;Return missing
Send4: ;spams key 4
	Send, 4
Return
Try:

Code: Select all

F5::
If SendActive := !SendActive
	SetTimer, Keys, 1000
Else
	SetTimer, Keys, Off
Pos := 0
Return
Keys:
Send,% [2,3,5,4,3][Pos:=1+Mod(Pos,5)]
Return

Borndo
Posts: 4
Joined: 21 Sep 2022, 10:49

Re: Missing Key in the Sequence

Post by Borndo » 27 Sep 2022, 09:56

Sorry for the late reply, but OH MY GOD! IT'S FINALLY WORKING AS INTENDED! Thank you so much good sir/ma'am!

Borndo
Posts: 4
Joined: 21 Sep 2022, 10:49

Re: Missing Key in the Sequence

Post by Borndo » 27 Sep 2022, 10:08

Good day again! What if I want to change the delay between 2 and 3? Instead of 1000 ms, it's 3000 ms. How do I make that work? I would also like to know what the definition and function of "Pos" is. Thank you.

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Missing Key in the Sequence

Post by Rohwedder » 28 Sep 2022, 02:13

Then:

Code: Select all

F5::
If SendActive := !SendActive
	SetTimer, Keys, 1000
Else
	SetTimer, Keys, Off
Pos := 0
Return
Keys:
Send,% [2,3,5,4,3][Pos:=1+Mod(Pos,5)]
SetTimer,,% 1000*[3,1,1,1,1][Pos]
Return
In Pos I store the current position within the (now two) Simple Arrays. E.g. the value 2 is in the array [2,3,5,4,3] at the 1st position, the value 3 at the 2nd and 5th position.
https://www.autohotkey.com/docs/Objects.htm#Usage_Simple_Arrays.
(Maybe it would be more speakable to use variable name "Key" instead of "Pos", since it addresses the contents of the arrays as a key.)

Code: Select all

MsgBox,% [2,3,5,4,3][3]
shows 5, because array [2,3,5,4,3] contains the Value "5" at the 3rd position, i.e. at Key = 3.

Post Reply

Return to “Gaming Help (v1)”