## Help with Variation Loop Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
guilhermevs91
Posts: 5
Joined: 03 Apr 2018, 11:54
GitHub: Guilherme

### Help with Variation Loop

Hello, gentlemen!

I would like to help with the following: I need to create a loop that when I press the F1 key, it is alternating between F8, F7, F8, F6 and restart, but I need to press it again to stop where it is. Example: Press F1. It will loop the F8, F7, F8, F6, F8, F7 and if I press the F1 again it will stop at that time and not finish the sequence. Would it be possible? detail that should have a time of 1 second between each key.

Thanks a lot for the help.
Sorry for the translator's english
Rohwedder
Posts: 2443
Joined: 04 Jun 2014, 08:33
Location: Germany

### Re: Help with Variation Loop  Topic is solved

Hallo,
try:

Code: Select all

``````Keys = {F8},{F7},{F8},{F6}
Keys := StrSplit(Keys,",")
Return
F1:: ;Send Keys On/Off with key F1
If F4Active:=!F4Active
SetTimer SendKeys, 1000 ;1000 ms delay between keys
Else
SetTimer SendKeys, Off
Return
SendKeys:
Counter := Mod(0 Counter,Keys.MaxIndex())+1
Send, % Keys[Counter]
Return``````
guilhermevs91
Posts: 5
Joined: 03 Apr 2018, 11:54
GitHub: Guilherme

### Re: Help with Variation Loop

Hi, thanks for the feedback, I took the test here and it did not work, do you have any other ideas?

Thanks for help!
Rohwedder wrote:Hallo,
try:

Code: Select all

``````Keys = {F8},{F7},{F8},{F6}
Keys := StrSplit(Keys,",")
Return
F1:: ;Send Keys On/Off with key F1
If F4Active:=!F4Active
SetTimer SendKeys, 1000 ;1000 ms delay between keys
Else
SetTimer SendKeys, Off
Return
SendKeys:
Counter := Mod(0 Counter,Keys.MaxIndex())+1
Send, % Keys[Counter]
Return``````
Xtra
Posts: 1558
Joined: 02 Oct 2015, 12:15

### Re: Help with Variation Loop

Example:

Code: Select all

``````#NoEnv

F1::
SetTimer SendKeys, % (t:=!t) ? 1000 : "Off"
Counter := toggle := 0
Return

SendKeys:
Send, %  Mod(++Counter,2) ? "{F8}" : (toggle:=!toggle) ? "{F7}" : "{F6}"
Return
``````
HTH
guilhermevs91
Posts: 5
Joined: 03 Apr 2018, 11:54
GitHub: Guilherme

### Re: Help with Variation Loop

I re-did the test and it worked!
SORRY!! AND THANK YOU SO MUCH!!

guilhermevs91 wrote:Hi, thanks for the feedback, I took the test here and it did not work, do you have any other ideas?

Thanks for help!
Rohwedder wrote:Hallo,
try:

Code: Select all

``````Keys = {F8},{F7},{F8},{F6}
Keys := StrSplit(Keys,",")
Return
F1:: ;Send Keys On/Off with key F1
If F4Active:=!F4Active
SetTimer SendKeys, 1000 ;1000 ms delay between keys
Else
SetTimer SendKeys, Off
Return
SendKeys:
Counter := Mod(0 Counter,Keys.MaxIndex())+1
Send, % Keys[Counter]
Return``````
Noo0B
Posts: 73
Joined: 26 Jan 2018, 19:54

### Re: Help with Variation Loop

Hi,
I'm glad you got it working.
I came up to a code for more general situations, it's something like this:

Code: Select all

``````F4::
Toggle:= !toggle
If Toggle {
While Toggle {
; code
}
Return
}
If !Toggle
; code
Return``````
EDIT:
I thought it was doing an extra line within the while-loop code after toggled off, but I could not replicate.
So it's good.
Regards