Author Topic: Detect Button and Keypresses (Double Press, Double Press and Hold(x ms)) etc.  (Read 1365 times)

Starblue7

  • Full Member
  • ***
  • Posts: 131
Hi.

I'm trying to find a way to determine various key presses and button presses within the following example types:

User Presses 'Y' twice and holds down for 2 seconds on the last press the Release (Double Press & Hold)
User Double Presses 'Y' Key quickly (Double Press)
User Presses 'Y' key once and holds for 2 seconds & Release  (Press & Hold x ms)

Same would go four controller button actions as well.

The outcome would be that based on the above occurrences, I would perform some other action or keypress.

I'm suspecting perhaps STATE_KEYSTATE may be involved.

Could someone give some advice?

Thanks!

EDIT:
This is all within an indefinite polling loop in order to capture various keypresses the user performs and then create a different outcome (keypress / action).

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Have a look at this topic.

The "{STATE_KEYSTATE:}" token has been largely superseded by the "Device State" tab for loops and conditions (which can be used for joystick/controller buttons as well).

Starblue7

  • Full Member
  • ***
  • Posts: 131
Thanks.  I think I've seen that snippet of code before.

Will look at it again a bit closer.

I just wish there was some simpler way to do this.
Like, perhaps have some option in the [Device State] dropdowns to include: 
- Is Pressed
- Is Not Pressed
- Is Only Key Pressed
- Is Double Pressed
- Is Doubled Pressed and Hold
- Is Pressed and Hold


To the right would be an entry box for the user to enter in milliseconds the pause duration for the 1st and 2nd presses.

Something like that would be awesome.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Looking at your examples again, this topic is probably closer to what you're looking for.

What you're looking to do is anything but simple, however. You're going to want to be very familiar with VoiceAttack's advanced features, and think through all the possible variations that may occur.
This is not something to undertake without understanding exactly what you're doing.

Starblue7

  • Full Member
  • ***
  • Posts: 131
Thanks.  You've given me a lot to chew on.
Unfortunately there are some cases I can't really avoid a double-press & hold combination.
As, this type of combination prevents some potentially very consequential results.
i.e.  hitting a key by mistake that has you exit your seat while in the heat of battle!

I suppose I could put in some MODIFIER + KEY (Or Button), but then that makes various actions more unwieldy in other ways..

Hmm...

Starblue7

  • Full Member
  • ***
  • Posts: 131
Looking at your examples again, this topic is probably closer to what you're looking for.

What you're looking to do is anything but simple, however. You're going to want to be very familiar with VoiceAttack's advanced features, and think through all the possible variations that may occur.
This is not something to undertake without understanding exactly what you're doing.

Hi.  Ok I think I'm mostly getting what's going on here.

The difference in my implementation is that the below is contained in an infinite loop that is kicked off on profile load automatically.

Thus I come to feel that this isn't necessary or needs to be revisited in my below script:
[>>{CMDWHENISAY}waitingForDouble] Equals True / False


Code: [Select]
            //// DoublePress & Hold and Double Press ////
            Begin Boolean Compare : [>>{CMDWHENISAY}waitingForDouble] Equals True
                Set date [~timeout] to [~timeout] plus [300] milliseconds
                Start Loop While : Keyboard Key 'Y' Is Pressed OR Keyboard Key 'Up Arrow' Is Pressed
                    //// DoublePress & Hold Command ////
                    Begin Date Compare : [~timeout] Is Before Current Date/Time
                        Execute command, '[Enter;Switch To;Enable;Engage] ONFOOT MODE; ONFOOT MODE' (and wait until it completes)
                        Say, 'Mode A - Double Press & Hold'  (and wait until it completes)
                    End Condition - Exit when condition met
                End Loop
                //// DoublePress Command ////
                Say, 'Mode A - Double Press TEST'  (and wait until it completes)
            End Condition - Exit when condition met
           
            //// Press & Hold Command ////
            Set date [~timeout] to [~timeout] plus [300] milliseconds
            Start Loop While : Keyboard Key 'Y' Is Pressed OR Keyboard Key 'Up Arrow' Is Pressed
                Begin Date Compare : [~timeout] Is Before Current Date/Time
                    Say, 'Mode A - Single Press and hold TEST'  (and wait until it completes)
                End Condition - Exit when condition met
            End Loop
           
            //// Single Press Command ////
            Set Boolean [>>{CMDWHENISAY}waitingForDouble] to True
            Start Loop While : Keyboard Key 'Y' Is Pressed OR Keyboard Key 'Up Arrow' Is Pressed
                Begin Date Compare : [~timeout] Is Before Current Date/Time
                    Say, 'Mode A - Single Press TEST'  (and wait until it completes)
                    Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False
                End Condition - Exit when condition met
            End Loop
            Set Boolean [>>{CMDWHENISAY}waitingForDouble] to False


Could you please take a looksie and let me know what simple errors I've made?   :-[

Starblue7

  • Full Member
  • ***
  • Posts: 131
Looking at your examples again, this topic is probably closer to what you're looking for.

What you're looking to do is anything but simple, however. You're going to want to be very familiar with VoiceAttack's advanced features, and think through all the possible variations that may occur.
This is not something to undertake without understanding exactly what you're doing.

Would your code from this thread be more relevant for my case?
https://forum.voiceattack.com/smf/index.php?topic=2339.0

Again, I'm not getting the need for the:
 Begin Boolean Compare : [{CMD}Running] Equals True

As I'm constantly looping.

The idea is to add in all the key presses (Single, Double, Double & Hold and Single Hold) for any keyboard keys and joystick button presses.
Whenever the users hits any of the keys or buttons that are on that list in relation to the above in parenthesis, it would kick off some other command.

Maybe I'm not being very clear, or maybe this is a stupid way to do this, or maybe it's just too complicated.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
What you're looking to do is anything but simple, however. You're going to want to be very familiar with VoiceAttack's advanced features, and think through all the possible variations that may occur.
This is not something to undertake without understanding exactly what you're doing.