Author Topic: Is Tap and Hold function possible?  (Read 5515 times)

AlphaZ3r0

  • Guest
Is Tap and Hold function possible?
« on: May 29, 2019, 06:49:00 PM »
I know that press, hold and double tap can be done in voice attack, but what about the hold function of a double tap, which is Tap and Hold (it's double tap, but hold the second tap)? I have seen it before, with Pinnacle Game Profiler, but wonder how I would set that up in VA if possible?

BTW, I have no coding experience, so please explain like I am 5  ;D

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Is Tap and Hold function possible?
« Reply #1 on: May 29, 2019, 07:13:45 PM »
Something like this could work:
Code: [Select]
Begin Date Compare : [>{CMDWHENISAY}pressTimeout] Is Greater Than Current Date/Time
    Set date [~holdTimeout] to [~holdTimeout] plus [150] milliseconds
    Start Loop While :  Keyboard Key 'Ctrl' Is Pressed
        Begin Date Compare : [~holdTimeout] Is Less Than Current Date/Time
            Write [Blue] 'Tap and hold registered' to log
        End Condition - Exit when condition met
    End Loop
Else
    Set date [>{CMDWHENISAY}pressTimeout] value to the current date/time
    Set date [>{CMDWHENISAY}pressTimeout] to [>{CMDWHENISAY}pressTimeout] plus [500] milliseconds
End Condition

The first compare checks whether the Date value stored in ">{CMDWHENISAY}pressTimeout" (the "{CMDWHENISAY}" token is used to make the name unique, so that multiple commands won't interfere with eachother) is within the time limit for registering a double tap (by checking whether the point set in the future previously is still in the future).

If so, a second value is set 150ms into the future, after which a loop checks whether the Ctrl key is held down. Inside the loop, a condition continually checks whether the 150ms have elapsed, and if so writes "Tap and hold registered" to the log (replace this with the actions you want to use).
Once that is done, the command will exit (to stop the loop; Otherwise chosen actions will continually run while you keep Ctrl held down).

If the Ctrl key were to be released before the 150ms have elapsed, the loop ends without the condition inside it executing its actions, and the command comes to a natural stop (by reaching the end of the action list).


If the first compare returns false, meaning either the key has not been pressed yet, or it hasn't been pressed within the last 500ms, ">{CMDWHENISAY}pressTimeout" is first set to the current time, then 500ms is added to it to define the point in the future beyond which a double tap will no longer be registered.



For a command like this, you could add the "Ignore an Unrecognized Word or Phrase" action at the top of the action list, so it doesn't show up in the log when you press the key (no log "spam" that way).

AlphaZ3r0

  • Guest
Re: Is Tap and Hold function possible?
« Reply #2 on: May 29, 2019, 08:11:24 PM »
Wow, thanks for the reply and the solution. And truly, thanks for explaining in a way I could understand. Now I will study this stuff to come up with my own commands... in due time, of course ;)

AlphaZ3r0

  • Guest
Re: Is Tap and Hold function possible?
« Reply #3 on: May 30, 2019, 06:26:05 PM »
Okay... so how would I combine this with Press, Press and Hold, Double Tap without triggering the Double Tap?

Code: [Select]
Begin Date Compare : [>{CMDWHENISAY}pressTimeout] Is Greater Than Current Date/Time
    Set date [~holdTimeout] to [~holdTimeout] plus [150] milliseconds
    Start Loop While :  Joystick 1 Button 28 Is Pressed
        Begin Date Compare : [~holdTimeout] Is Less Than Current Date/Time
            Double Tap and Hold command here
            Execute command, 'WING 2' (and wait until it completes)
        End Condition - Exit when condition met
    End Loop
Else
    Set date [>{CMDWHENISAY}pressTimeout] value to the current date/time
    Set date [>{CMDWHENISAY}pressTimeout] to [>{CMDWHENISAY}pressTimeout] plus [500] milliseconds
End Condition
Begin Boolean Compare : [{CMD}Running] Equals True
End Condition - Exit when condition met
Set Boolean [{CMD}Running] to True
Set date [~commandStart] to [~commandStart] plus [300] milliseconds
Start Loop While : (Joystick 1 Button 28 Is Pressed AND [~commandStart] Is Greater Than Current Date/Time)
End Loop
Begin Date Compare : [~commandstart] Is Less Than Current Date/Time
    Press and hold command here
    Execute command, 'WING 1 NAVLOCK;NAVLOCK WING 1' (and wait until it completes)
Else
    Start Loop While : [~commandStart] Is Greater Than Current Date/Time
        Begin Device State Check :  Joystick 1 Button 28 Is Pressed
            Double tap command here
            Execute command, 'WING 1 TARGET;WING ONE'S TARGET' (and wait until it completes)
            Set Boolean [{CMD}Running] to [Not Set]
        End Condition - Exit when condition met
    End Loop
    Press command here
    Execute command, 'WING 1;WINGMAN 1' (and wait until it completes)
End Condition
Set Boolean [{CMD}Running] to [Not Set]


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Is Tap and Hold function possible?
« Reply #4 on: May 30, 2019, 07:48:10 PM »
Okay... so how would I combine this with Press, Press and Hold, Double Tap without triggering the Double Tap?

You could have mentioned that requirement beforehand...


Here's one way to do all four in one command:
Code: [Select]
Begin Boolean Compare : [>>{CMDWHENISAY}waitingForDouble] Equals True
    Set date [~timeout] to [~timeout] plus [300] milliseconds
    Start Loop While :  Keyboard Key 'Ctrl' Is Pressed
        Begin Date Compare : [~timeout] Is Less Than Current Date/Time
            Write [Blue] 'Double tap Hold registered' to log
        End Condition - Exit when condition met
    End Loop
    Write [Blue] 'Double tap registered' to log
End Condition - Exit when condition met
Set date [~timeout] to [~timeout] plus [300] milliseconds
Start Loop While :  Keyboard Key 'Ctrl' Is Pressed
    Begin Date Compare : [~timeout] Is Less Than Current Date/Time
        Write [Blue] 'Hold registered' to log
    End Condition - Exit when condition met
End Loop
Set Boolean [>>{CMDWHENISAY}waitingForDouble] to True
Start Loop While :  Keyboard Key 'Ctrl' Is Not Pressed
    Begin Date Compare : [~timeout] Is Less Than Current Date/Time
        Write [Blue] 'Press registered' to log
        Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False
    End Condition - Exit when condition met
End Loop
Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False

The one quirk I've found is that the first time the command is used in a session (I.E. after loading the profile initially; if you switch away and back, the command does work correctly), if you quickly double tap (or, double tap and hold) it'll register as two presses (or holds), which isn't supposed to be possible as ">>{CMDWHENISAY}waitingForDouble" would normally be set before the second command even fires.

I can only assume something is getting loaded internally within VoiceAttack during the first execution of the command, causing a delay leading to a race condition where the second command is able to run before the first has set that variable.

I tried without the token (or scope) in the command name, that makes no difference.

EPMD

  • Newbie
  • *
  • Posts: 3
Re: Is Tap and Hold function possible?
« Reply #5 on: March 21, 2020, 09:38:03 AM »
Nice. This command technically does what I want, except I have no idea how to make this work with a joystick, or in my case, execute another command. Here's what I want this command to do:

We'll use 'Joystick 1 Button 1' (J1B1)for our single button example.

I 'Press' J1B1, it executes one of the commands that I have already set up in Voice Attack. The same thing happens when I 'Hold', 'Double Tap' and 'Double Tap Hold' J1B1... all different commands.

How do we set this up in VA?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Is Tap and Hold function possible?
« Reply #6 on: March 21, 2020, 12:57:17 PM »
It should be no different. Literally the only changes required are to select "Joystick 1 Button" from the dropdown on the "Device State" tab instead of "Keyboard Key", and the appropriate button from the second dropdown (and executing the command using that button as the trigger, obviously).

EPMD

  • Newbie
  • *
  • Posts: 3
Re: Is Tap and Hold function possible?
« Reply #7 on: March 21, 2020, 08:23:07 PM »
Thanks for the reply. Just got home to try out the command, and this is what I have:

'Press' & 'Hold' work as intended, however, when doing the Double Tap (DT) command, it not only gives the DT command, but the 'Press' command as well.

Also, instead of the Double Tap Hold command, I get the Hold command twice. This is what I have below...

Code: [Select]
Begin Boolean Compare : [>>{CMDWHENISAY}waitingForDouble] Equals True
    Set date [~timeout] to [~timeout] plus [300] milliseconds
    Start Loop While :  Joystick 1 Button 1 Is Pressed
        Begin Date Compare : [~timeout] Is Less Than Current Date/Time
            'DoubleTap & HOLD' command below
            Execute command, 'BALANCE POWER;BALANCE' (and wait until it completes)
            Write [Blue] 'DoubleTap HOLD registered' to log
        End Condition - Exit when condition met
    End Loop
    'DoubleTap' command below
    Execute command, 'WING 3' (and wait until it completes)
    Write [Blue] 'DoubleTap registered' to log
End Condition - Exit when condition met
Set date [~timeout] to [~timeout] plus [300] milliseconds
Start Loop While :  Joystick 1 Button 1 Is Pressed
    Begin Date Compare : [~timeout] Is Less Than Current Date/Time
        'HOLD' command below
        Execute command, 'WING 2' (and wait until it completes)
        Write [Blue] 'HOLD registered' to log
    End Condition - Exit when condition met
End Loop
Set Boolean [>>{CMDWHENISAY}waitingForDouble] to True
Start Loop While :  Joystick 1 Button 1 Is Not Pressed
    Begin Date Compare : [~timeout] Is Less Than Current Date/Time
        'PRESS' command below
        Execute command, 'WING 1;WINGMAN 1' (and wait until it completes)
        Write [Blue] 'PRESS registered' to log
        Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False
    End Condition - Exit when condition met
End Loop
Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False

UPDATE: After I tried using different presses to see if it would register the Double Tap and the Double Tap Hold commands, it appears that the timings are very strict. Both Double Tap and Double Tap Hold requires lightning speed to execute (which is not what I want). What the Double Tap Hold requires is actually a Triple Tap Hold(3 'Presses' with the last being held) instead of the Double Tap Hold, which is 2 'Presses' with the last being held to execute the command.




Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Is Tap and Hold function possible?
« Reply #8 on: March 21, 2020, 09:05:24 PM »
First thing you'll want to do is update your VoiceAttack installation. You're running an outdated version (which may not be the reason this command isn't working, though I can't get it to break in the manner you're describing on the latest stable or the latest beta).

Do make sure you have the evaluation options set so they result in the default value for their datatype if the value is "Not Set", E.G. "Evaluate 'Not Set' as false" and "Evaluate 'Not Set' as 1/1/0001".


If the double tap timeout is too short, you can easily increase it, at the cost of having to wait longer for a single press to be registered (as is always the case with a system that registers multiple keypresses).
« Last Edit: March 22, 2020, 08:50:21 AM by Pfeil »

EPMD

  • Newbie
  • *
  • Posts: 3
Re: Is Tap and Hold function possible?
« Reply #9 on: March 22, 2020, 08:39:04 AM »
 :o El Oh El.

This was spot on. Outdated version indeed, once I changed the appropriate settings to Not Set, everything just worked.
Thanks so much for your help and your patience.

BTW, I would love to learn how to code for VA.

I've heard some people say C, C++... I know none of it, so what specifically should I study to know how to do this for VA.
Thanks again for all of your help, I really appreciate it.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Is Tap and Hold function possible?
« Reply #10 on: March 22, 2020, 08:50:07 AM »
VoiceAttack itself is written in C#, and supports plugins and inline functions written in C# or VB.NET

Personally I would recommend looking into C#, which is the most commonly used language in the community.