Author Topic: Consecutive Inputs  (Read 3725 times)

Mineman

  • Guest
Consecutive Inputs
« on: February 27, 2019, 06:15:54 AM »
I have no clue what to call this or if it's even possible, but I recently downloaded VoiceAttack and I'm trying to set up a profile for Space Engineers.  I know how to do the easy stuff like open certain menus when I give a command, but cant figure out how to get it to press a different number if I issue a command.  For instance, to change panels in Space Engineers, you press CTRL plus 1-0 depending on whichever panel you want.  You can't just use the scroll wheel to go through the panels.  If I'm on panel #1 and I want to go to panel #2, I want to be able to just say "Next Panel."  If I'm on Panel #1 and I want to skip to panel #5, I would like to say either "panel 5" or "advance to panel 5."

Does anybody here know how to do that?  Is that even possible?

Thanks in advance!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Consecutive Inputs
« Reply #1 on: February 27, 2019, 09:51:53 AM »
You'll want to use an integer variable to keep track of the selected panel, which you can then increment or decrement for next/previous.

If you add a command to that triggered by pressing Ctrl, that checks which numeric key(s) are pressed, you can also update the value when you use the keyboard to change panels(to prevent the internal value from losing sync with the game's value).

As you can select panels directly with a keypress, the direct "panel 5" command can overwrite the value with whatever number you've spoken after pressing the key combination.


A command like this should do all that:
next panel;previous panel;panel [0..9]
Code: [Select]
Begin Text Compare : [{CMDACTION}] Equals 'Keyboard'
    Start Loop While :  Keyboard Key 'Ctrl' Is Pressed
        Begin Device State Check :  Keyboard Key '1' Is Pressed
            Set integer [>>currentPanel] value to 1
        Else If Device State Check :  Keyboard Key '2' Is Pressed
            Set integer [>>currentPanel] value to 2
        Else If Device State Check :  Keyboard Key '3' Is Pressed
            Set integer [>>currentPanel] value to 3
        Else If Device State Check :  Keyboard Key '4' Is Pressed
            Set integer [>>currentPanel] value to 4
        Else If Device State Check :  Keyboard Key '5' Is Pressed
            Set integer [>>currentPanel] value to 5
        Else If Device State Check :  Keyboard Key '6' Is Pressed
            Set integer [>>currentPanel] value to 6
        Else If Device State Check :  Keyboard Key '7' Is Pressed
            Set integer [>>currentPanel] value to 7
        Else If Device State Check :  Keyboard Key '8' Is Pressed
            Set integer [>>currentPanel] value to 8
        Else If Device State Check :  Keyboard Key '9' Is Pressed
            Set integer [>>currentPanel] value to 9
        Else If Device State Check :  Keyboard Key '0' Is Pressed
            Set integer [>>currentPanel] value to 0
        End Condition
    End Loop
End Condition - Exit when condition met

Begin Integer Compare : [>>currentPanel] Has Not Been Set
    Set integer [>>currentPanel] value to 1
End Condition

Begin Text Compare : [{CMD}] Contains 'next'
    Begin Integer Compare : [>>currentPanel] Equals 9
        Set integer [>>currentPanel] value to 0
    Else
        Set integer [>>currentPanel] to [>>currentPanel] plus 1
    End Condition
Else If Text Compare : [{CMD}] Contains 'previous'
    Begin Integer Compare : [>>currentPanel] Equals 0
        Set integer [>>currentPanel] value to 9
    Else
        Set integer [>>currentPanel] to [>>currentPanel] minus 1
    End Condition
Else
    Set integer [>>currentPanel] value to the converted value of {TXTNUM:"{CMD}"}
End Condition

Quick Input, '[CTRLDOWN]{INT:>>currentPanel}[CTRLUP]'

The initial value when VoiceAttack starts would be 0; I included actions to set it to 1, assuming that's what the game starts with.
If the game remembers the previously selected panel across sessions, you'll want to look into saving values to the profile so you can do this for VoiceAttack as well.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Consecutive Inputs
« Reply #2 on: February 27, 2019, 10:20:49 AM »
Pfeil beat me to it, so I'll just provide a few additional bits. 

If you want something flexible and you want to always provide the panel you need (no "next" or "previous") you can use a dynamic command (help document page 17) that extracts numeric input from what you spoke (token {TXTNUM:} on help document page 135) and converts that into a variable key press (help document pages 29 and 152). 

When I say: Panel [0..5]
Code: [Select]
// Construct the input text for variable keypress based on numeric data from recognized command
Set Text [~~VarKeypress] to '[CTRL]{TXTNUM:"{CMD}"}'

// Perform a variable keypress
Press variable key(s) [~~VarKeypress] and hold for 0.06 seconds and release

So basically this will press CTRL+X, with X depending on what you said in the command (here ranging from 0 to 5). Again, Pfeil's example handles this case (and a lot more!), but I wanted to point out the Variable Keypress functionality as well as specific stuff to check out in the help manual.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Consecutive Inputs
« Reply #3 on: February 27, 2019, 12:14:48 PM »
Not sure I see the advantage of Variable Keypress over Quick Input.

I used the latter to save on setting a text variable(as the value will not be re-used in text form), which could also apply for a direct option:
Code: [Select]
Quick Input, '[CTRLDOWN]{TXTNUM:"{CMD}"}[CTRLUP]'

Mineman

  • Guest
Re: Consecutive Inputs
« Reply #4 on: February 27, 2019, 06:55:22 PM »
Oh wow!  Awesome!  Thanks for the quick replies folks!  When I get home, I'll give this a shot and let you know how it goes.  It looks like I need to learn how to code or something..?

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Consecutive Inputs
« Reply #5 on: February 28, 2019, 09:18:02 AM »
VA's command actions are implemented through VA's UI and everything is explained well in the help document, so particular coding experience is not required. However, it is useful to understand some fundamental programming concepts like variable types (integers, strings [text], booleans, etc.), looping, and if statements (again, the manual is helpful here). You can provide C# or VB.NET code through a plugin or inline function to do some wild stuff, but VA's native functionality is usually more than enough to meet most needs.

The blocks of "code" that Pfeil and I posted are just VA actions copied from the UI as text, since this format is generally the best for readability on the forum. The stuff I shared actually looks like this:



Unfortunately you cannot simply paste in what we provided, you have to use the info as a guide and manually create the actions yourself using the UI.