Author Topic: Button push and hold  (Read 8066 times)

terrydew

  • Jr. Member
  • **
  • Posts: 54
Button push and hold
« on: November 14, 2016, 02:11:54 PM »
I am using VA for button assignments on my joystick. I want to assign a key press when the trigger is pulled and have that key repeat while the trigger is held and stop when it is released. The only way I have found (other than having two commands) is to use a loop based on the trigger state. This works but I am wondering if there is an easier way to do it? There is no "hold" option for the button assignment that I can see?

Thanks for any help.
Terry

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Button push and hold
« Reply #1 on: November 14, 2016, 02:29:01 PM »
I think you've covered the options here.

A command that starts when the button is pressed(Shortcut is invoked only when all buttons are released unchecked), containing something like the following:
Code: [Select]
Start Loop While : [{STATE_JOYSTICK1BUTTON:1}] Equals '1'
    Press A key and hold for 0,06 seconds and release
End Loop
Is the simplest way to accomplish a repeating keypress while the button is held down.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Button push and hold
« Reply #2 on: November 14, 2016, 03:49:11 PM »
You have to use a loop as Pfeil has described as the repeat you normally experience is provided by hardware.

terrydew

  • Jr. Member
  • **
  • Posts: 54
Re: Button push and hold
« Reply #3 on: November 14, 2016, 08:26:20 PM »
I think you've covered the options here.

A command that starts when the button is pressed(Shortcut is invoked only when all buttons are released unchecked), containing something like the following:
Code: [Select]
Start Loop While : [{STATE_JOYSTICK1BUTTON:1}] Equals '1'
    Press A key and hold for 0,06 seconds and release
End Loop
Is the simplest way to accomplish a repeating keypress while the button is held down.

Thanks. Question I tried to use the state token directly in the loop command but it gave me a error saying the variable couldn't have a colon in it? I think I was using the integer tab? Do you have to enclose the token in anything.
Edit Nevermind I see you have to use the txt tab even though the token returns a number!

Thank you for your help.
Terry
« Last Edit: November 15, 2016, 11:19:06 AM by terrydew »

terrydew

  • Jr. Member
  • **
  • Posts: 54
Re: Button push and hold
« Reply #4 on: November 14, 2016, 08:36:13 PM »
You have to use a loop as Pfeil has described as the repeat you normally experience is provided by hardware.

I sure wish you would consider adding a hold option to the button select dialog so the command could be a simple key press. I am trying to use VA to replace the Thrustmaster Target software and a lot of functions require a repeat while button held feature.

Thanks
Terry

samdd1965

  • Newbie
  • *
  • Posts: 1
Re: Button push and hold
« Reply #5 on: August 27, 2021, 07:12:36 PM »
Even though this is an old post, I am replying in case it is helpful to someone who like me needs the ability to hold down a key like say [SHIFT] for sprinting and not just for repeating.

The following will work for both repeating and holding the key down.
Use the same method described above but replace the timed keypress with a hold keypress and then end it with an additional line of release keypress.

It should look like this when completed:

Start Loop While : [{STATE_JOYSTICK1BUTTON:1}] Equals '1'
    Press Down Left Shift key
End Loop
Release Left Shift key

Also note that the loop is selected in the button/menu
Other\Advanced\Add a loop start\Single condition (while loop).
And as noted by the previous post you need to use the [Text] tab.
Make sure to include ONLY the {curly brackets} around the variable\token. I.e., {STATE_JOYSTICK1BUTTON:1}

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Button push and hold
« Reply #6 on: August 27, 2021, 07:30:39 PM »
That is not required for holding down a key to match a button state on a joystick. You're pressing the key repeatedly within the loop, essentially spamming that press, which is unnecessary in the majority of cases.

The "{STATE_" series of tokens has also been superseded (aside from niche use) by the "Device State" tab in loop/condition actions.


This would be the current method:
Code: [Select]
Press down Left Shift key
Start Loop While :  Joystick 1 Button 1 Is Pressed
End Loop
Release Left Shift key

Murble

  • Newbie
  • *
  • Posts: 4
Re: Button push and hold
« Reply #7 on: October 08, 2021, 07:38:20 AM »
That is not required for holding down a key to match a button state on a joystick. You're pressing the key repeatedly within the loop, essentially spamming that press, which is unnecessary in the majority of cases.

The "{STATE_" series of tokens has also been superseded (aside from niche use) by the "Device State" tab in loop/condition actions.


This would be the current method:
Code: [Select]
Press down Left Shift key
Start Loop While :  Joystick 1 Button 1 Is Pressed
End Loop
Release Left Shift key

Reviving this post again to say I can't get this to work.
Currently what I am trying to do is make it so while you hold the left mouse button it will press the left mouse button every 0.2 seconds (Trying to make a controlled fire command).

So far, the command is triggered when I press C, I have it repeat continuously until stopped which it stops when you press C again. This part I have works.

However, inside the command I put:
Code: [Select]
Start Loop While :  Left Mouse Button Is Pressed
    Say, 'Fire'
    Pause 0.05 seconds
End Loop
(Currently using the Say, Fire just as a testing bit)
This worked perfectly, spamming the word fire while I hold the left mouse button.

But, when I add in the command to click the left mouse button as well, making it:
Code: [Select]
Start Loop While :  Left Mouse Button Is Pressed
    Click left mouse button
    Say, 'Fire'
    Pause 0.05 seconds
End Loop
It only fires once, then stops.

I assume this is because the Click left mouse button command presses the button down then lets it back up, which since the while loop is meant to only continue while it's pressed, stops it. When I change it so the while loop waits for middle mouse button is held, it works.

So, I know the problem has to do with clicking the same button as what the while loop is looping for. Is there a way around this other then assigning a different key to the while loop? I like to be able to click the same fire button.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Button push and hold
« Reply #8 on: October 08, 2021, 08:12:28 AM »
You could use a command that triggers when the mouse button is released, which stops the command running the loop

E.G.
Code: [Select]
Do nothing (ignore command)
Begin Text Compare : [{CMDACTIVE:mouse click command}] Equals '1'
    Kill command, 'mouse click command'
    Release left mouse button
End Condition

The command running the loop could use the "Repeating" option to "Repeat continuously until stopped" rather than an actual loop action, if all you need is a click and a pause. Either way, it should not check the state of the mouse button while looping.

Murble

  • Newbie
  • *
  • Posts: 4
Re: Button push and hold
« Reply #9 on: October 08, 2021, 08:44:08 AM »
You could use a command that triggers when the mouse button is released, which stops the command running the loop

E.G.
Code: [Select]
Do nothing (ignore command)
Begin Text Compare : [{CMDACTIVE:mouse click command}] Equals '1'
    Kill command, 'mouse click command'
    Release left mouse button
End Condition

The command running the loop could use the "Repeating" option to "Repeat continuously until stopped" rather than an actual loop action, if all you need is a click and a pause. Either way, it should not check the state of the mouse button while looping.
I actually found an option which seems built for this. If you have the command execute when you press the left mouse button, there is an option for 'Repeat command while buttons are held down', you have to disable 'Do not allow button event to be passed through' to set it.

Then my command just looks like:
Code: [Select]
Click left mouse button
Pause 0.065 seconds

If you want to toggle between control fire and free fire, you can simply make a bool which is toggled in another command which is executed when you press a key.