Author Topic: Create native options to detect double taps, and press and hold functions  (Read 5266 times)

Malic

  • Full Member
  • ***
  • Posts: 105
What I am imagining would be a native option in the "add a command" section to detect a double tap or pressing and holding a button.

Examples of how I would use these would be for example, with the upcoming Elite Dangerous 3.3 update:

The button I use to target ships, if I press and hold it instead, would activate the analysis mode.


Could also make a single button do up to three different things:

Example:
Single press: Chaff
Double press: Cargo Scoop
Press and hold: Landing Gear

Second example:
Single press: Lights
Douple press: N/A
Press and hold: Night vision

Much like the ability to use the {CMDSEGMENT:0} Token to have the command grab what word was said, might need to make a new Token type to have it check to see if the button press was a single press, double tap or a press and hold so you can make a single command that could do all the different things.

Also would need options to be able to customize how quickly the double tap needs to be to be registered as a double tap, and how long the button needs to be held too.  Am thinking 1000 = 1 second ( 200 would be "standard" for most double taps/clicks

Might be able to use this for detecting mouse clicks and joystick buttons as well.


EDIT by Pfeil: Double tap/hold/double tap hold functionality has been implemented.
« Last Edit: April 18, 2020, 12:31:22 PM by Pfeil »

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Create native options to detect double taps, and press and hold functions
« Reply #1 on: November 30, 2018, 06:17:18 AM »
I agree, it would be cool if it could be integrated in to va.

If you would like a press and hold function though. Here is my well tested one. It allows for single taps, and press and hold actions.

Code: [Select]
Set small int (condition) [Seconds] value to 0
Start Loop While :  Keyboard Key 'F14' Is Pressed
    Set small int (condition) [Seconds] value as incremented by 1
    Write [Blue] '{SMALL:Seconds}' to log
    Pause 0.1 seconds
    Begin Small Integer Compare : [Seconds] Is Greater Than 3
    Put here the press and hold command to be run!
    End Condition - Exit when condition met
End Loop
Begin Small Integer Compare : [Seconds] Is Less Than 3
    Here for single tap commands
End Condition - Exit when condition met

Begin Small Integer Compare : [Seconds] Is Less Than 3
End Condition - Exit when condition met

^ This really isn't needed, because it will happen by default if Seconds never reaches 4. 4 would be 0.4 seconds. Most normal single key presses are under 0.3 seconds. Fast key presses are under 0.1 seconds.

The time delay, is just long enough, that you never accidentally trigger the press and hold command, but also, that you don't feel like you're holding the key down for a long time either. I've been using this for a long time, and works great. I actually have a command just with this command in it, so I can copy and paste it into other commands. I use a 20 button mouse, and most every button now has 2 possible trigger actions.

I decided to make a profile for just this command, and attached it for download. Hope it comes in handy for you, and others. Very useful command.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Create native options to detect double taps, and press and hold functions
« Reply #2 on: November 30, 2018, 11:15:25 PM »
Here's one way of implementing all three functions into a command:

Code: [Select]
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 : (Keyboard Key 'F14' Is Pressed AND [~commandStart] Is Greater Than Current Date/Time)
End Loop
Begin Date Compare : [~commandStart] Is Less Than Current Date/Time
    Execute command, 'press and hold command' (by name)
Else
    Start Loop While : [~commandStart] Is Greater Than Current Date/Time
        Begin Device State Check :  Keyboard Key 'F14' Is Pressed
            Execute command, 'double tap command' (by name)
            Set Boolean [{CMD}Running] to [Not Set]
        End Condition - Exit when condition met
    End Loop
    Execute command, 'press command' (by name)
End Condition
Set Boolean [{CMD}Running] to [Not Set]


The command must check for a running instance and stop itself if there is one already, as the double tap will run the command again(you can uncheck the "Allow other command to execute while this one is running and do away with the check, but that may not be desirable).

Waiting for a second press also necessitates waiting before executing the single press command, meaning in this example ±300ms will elapse between the initial keypress and continuation of the command.

Malic

  • Full Member
  • ***
  • Posts: 105
Re: Create native options to detect double taps, and press and hold functions
« Reply #3 on: December 07, 2018, 03:00:06 PM »
Only question I have about the above,

this line:

Quote
Begin Device State Check :  Keyboard Key 'F14' Is Pressed


Because of all the different control setups, am trying to make my profile as pain free as I can so if I have this on my joystick, and I press it, vs holding it down it will toggle lights, or toggle night vision if held.

But

With this, does each user require that they manually change that line on their control, or is there a way to have this automatically change to the button that is being pressed in the "When I press" portion of the command?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Create native options to detect double taps, and press and hold functions
« Reply #4 on: December 07, 2018, 04:22:14 PM »
With this, does each user require that they manually change that line on their control, or is there a way to have this automatically change to the button that is being pressed in the "When I press" portion of the command?
Yes, they'll have to manually change it. No there is no way to automatically set it to whatever's mapped to trigger the command.

I requested the latter some time ago, so it may make its way in, still.

FR4NK7Y

  • Newbie
  • *
  • Posts: 11
Re: Create native options to detect double taps, and press and hold functions
« Reply #5 on: February 28, 2022, 12:50:33 PM »
Shouldnt "Greater then" and "Less then" be "is after" and "is before"?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Create native options to detect double taps, and press and hold functions
« Reply #6 on: February 28, 2022, 12:52:11 PM »
In the current version, yes. That example was written using an older version.

FR4NK7Y

  • Newbie
  • *
  • Posts: 11
Re: Create native options to detect double taps, and press and hold functions
« Reply #7 on: February 28, 2022, 01:22:49 PM »
Did something else change? I cant get the double-tab to work.
I tried changing stuff and googled before asking. :D

Code: [Select]
Begin Boolean Compare : [{CMD}Running] Equals True
End Condition - Exit when condition met
Set Boolean [{CMD}Running] to True
Set date [~usr1.joystick1.button5] to [~usr1.joystick1.button5] plus [250] milliseconds
Start Loop While : (Joystick 1 Button 5 Is Pressed AND [~usr1.joystick1.button5] Is After Current Date/Time)
End Loop
Begin Date Compare : [~usr1.joystick1.button5] Is Before Current Date/Time
    Start Loop While :  Joystick 1 Button 5 Is Pressed
        Press down Left Shift key
    End Loop
    Release Left Shift key
Else
    Start Loop While : (Joystick 1 Button 5 Is Pressed AND [~usr1.joystick1.button5] Is Before Current Date/Time)
        Begin Device State Check :  Joystick 1 Button 5 Is Pressed
            Press H key and hold for 0,1 seconds and release
            Set Boolean [{CMD}Running] to [Not Set]
        End Condition - Exit when condition met
    End Loop
    Press U key and hold for 0,1 seconds and release
End Condition
Set Boolean [{CMD}Running] to [Not Set]

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Create native options to detect double taps, and press and hold functions
« Reply #8 on: February 28, 2022, 01:40:45 PM »
The command should still work. Backward-compatibility is normally maintained.

However, you added an "AND" to the loop just after the "Condition Else" action, which may be relevant

FR4NK7Y

  • Newbie
  • *
  • Posts: 11
Re: Create native options to detect double taps, and press and hold functions
« Reply #9 on: February 28, 2022, 01:46:44 PM »
Ah mah gawd, I did not see that...

Edit: actually i found a few errors... i'll report back!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Create native options to detect double taps, and press and hold functions
« Reply #10 on: February 28, 2022, 01:50:54 PM »
That is part of why it's important to understand how a command actually functions.


As an aside, changing the name of the "~commandStart" variable makes no difference, but there is also no point in doing so.
It is explicitly command-scoped, so that the same variable name can be used in multiple commands while still creating separate instances, I.E. the data is only available in the command instance it's used in, so one will not affect the other.

FR4NK7Y

  • Newbie
  • *
  • Posts: 11
Re: Create native options to detect double taps, and press and hold functions
« Reply #11 on: February 28, 2022, 01:57:54 PM »
Allrighty then! Sometimes I feel stupid for asking stuff. But its working now. Thank you. :D