Author Topic: Infinite loop command started and paused with the same key  (Read 1886 times)

Ozias

  • Newbie
  • *
  • Posts: 6
Infinite loop command started and paused with the same key
« on: December 28, 2023, 01:27:34 PM »
I'm trying to set up an infinite loop command where let's say it presses 1, 2, 3 ,4 ,5 over and over infinitely. How would I be able to set the loop to be started with "Z" key and also be paused with that same "Z" key? So, after the "Z" key is pressed to start it, it is then used to also pause and then unpause the loop from running. Thank you so much for the help!!!

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Infinite loop command started and paused with the same key
« Reply #1 on: December 28, 2023, 05:41:12 PM »
You would want to make a command that is triggered ('When I press keys') with the Z key, with the 'Repeat command while keys are held down' option selected.  The actions in the command itself press each of your keys.

Hope that helps!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Infinite loop command started and paused with the same key
« Reply #2 on: December 29, 2023, 01:05:51 AM »
If you want the loop to literally pause, so it'll press the next key in the sequence rather than always starting with the first key in the sequence, something like this could work:
Code: [Select]
Begin Text Compare : [{CMDALREADYEXECUTING}] Equals '1'
    Set Boolean [>{CMD}PauseLoop] to Toggle
Else
    Set Boolean [>{CMD}PauseLoop] to False
End Condition - Exit when condition met
Start Indefinite Loop
    Press 1 key and hold for 0,1 seconds and release
    Start Loop While : [>{CMD}PauseLoop] Equals True
    End Loop
    Press 2 key and hold for 0,1 seconds and release
    Start Loop While : [>{CMD}PauseLoop] Equals True
    End Loop
    Press 3 key and hold for 0,1 seconds and release
    Start Loop While : [>{CMD}PauseLoop] Equals True
    End Loop
    Press 4 key and hold for 0,1 seconds and release
    Start Loop While : [>{CMD}PauseLoop] Equals True
    End Loop
    Press 5 key and hold for 0,1 seconds and release
    Start Loop While : [>{CMD}PauseLoop] Equals True
    End Loop
End Loop

Note that the command will keep running in the background, so if you want to stop it completely you'll need to either stop all commands, or use an additional command that specifically stops this one.
If you do fully stop this command, it'll start at the first key in the sequence again.

Not necessarily the most efficient approach, but should be relatively simple to implement.

Ozias

  • Newbie
  • *
  • Posts: 6
Re: Infinite loop command started and paused with the same key
« Reply #3 on: December 30, 2023, 01:37:34 PM »
Thank you SO much for trying to help and hopefully this info helps others, but it's not quite what I'm looking to do. To be more clear on what I'm attempting: I'm trying to setup an infinite looping macro that is both toggled on and off by pressing the same key once (not holding it down). So for this example let's say I want it to press 1,2,3,4,5 with a one second pause in between looping infinitely. To both start and stop the loop I'd like it to be the same key, for this example let's use "z". So if I press and release "z" it starts the 1,2,3,4,5 loop forever, if I press "z" a second time it stops it (or pauses in the middle to be unpaused again from that spot or simply to stop the command to be restarted from the beginning, whichever is easier to setup). As long as pressing "z" once and releasing can both start and stop the infinite loop. So if I press "z' once it starts and goes forever, then later if I press "z" for a second time it stops. If I press "z" again a third time it starts again (even if it starts over at the beginning or from where it left off, whichever is easier to setup) and the 4th time I press "z" it stops again...etc. Thanks again for all your help and hopefully this helps others who want to set up infinite loops that are toggled on/off with one key! :)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Infinite loop command started and paused with the same key
« Reply #4 on: December 30, 2023, 01:41:16 PM »
Have you actually tried the command I posted? Pretty what you're describing is exactly what it does...

Ozias

  • Newbie
  • *
  • Posts: 6
Re: Infinite loop command started and paused with the same key
« Reply #5 on: January 01, 2024, 08:26:34 AM »
Yes, I did before. It was quite a task to find out how to put all those lines in but I figured out how. It didn't seem to work, probably because I was in over my head. I'll try again though.