Author Topic: ‘Repeat command while keys are held down’  (Read 1416 times)

Starblue7

  • Full Member
  • ***
  • Posts: 131
‘Repeat command while keys are held down’
« on: March 14, 2023, 06:26:09 AM »
Will the above-subject option allow variables to persist in the command?
Or does it reset everything and run again?

I'm looking to make a command that will:
Detect how long the user holds down the UP button and if it reaches 5 seconds, have another key pressed and held at the same time until the user let's up on the UP key again.

Can I accomplish this with the above option? Or must I make some loop within the command itself to do this?

Could anyone give me a simply example of how I can accomplish the above?

Thanks!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: ‘Repeat command while keys are held down’
« Reply #1 on: March 15, 2023, 12:29:41 PM »
The "Repeat command while keys are held down" option could theoretically be used, however it's likely not the most practical solution.

Variables do persist between repetitions when using that option, as it remains the same instance of the command.


A possible option using loops could look something like this:
Code: [Select]
Set date [~holdTimeout] to [~holdTimeout] plus [5] seconds
Start Loop While :  Keyboard Key 'Up Arrow' Is Pressed
    Begin Date Compare : [~holdTimeout] Is Before Current Date/Time
        Press down A key
        Start Loop While :  Keyboard Key 'Up Arrow' Is Pressed
        End Loop
        Release A key
    End Condition - Exit when condition met
End Loop

Starblue7

  • Full Member
  • ***
  • Posts: 131
Re: ‘Repeat command while keys are held down’
« Reply #2 on: March 15, 2023, 04:50:42 PM »
Thanks @Pfeil

It wasn't clear to me when looking at the manual for the 'Repeat command while keys are held down' how variables would operate within such a loop.

Admittedly I'm not yet up to speed with how variables are handled within VoiceAttack.

------------------

Thanks for the above code snippet.

Though related, I've since pivoted in a new direction, which, may warrant a different post, as I'm having some trouble getting keys sorted as to when being in a released state or not.

I'll make a new post and ask for the community's suggestion regarding how to handle it.
Very much appreciate any input you may have as well.

Thanks!