Page 1 of 1

### Help with Variation Loop

Posted: 29 Jun 2018, 10:45
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

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

Posted: 29 Jun 2018, 22:30
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``````

### Re: Help with Variation Loop

Posted: 30 Jun 2018, 13:19
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``````

### Re: Help with Variation Loop

Posted: 30 Jun 2018, 14:35
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

### Re: Help with Variation Loop

Posted: 30 Jun 2018, 14:36
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``````

### Re: Help with Variation Loop

Posted: 01 Jul 2018, 01:37
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