Author Topic: Dictating the number of times to move the arrow keys?  (Read 1285 times)

DzedDonut

  • Newbie
  • *
  • Posts: 3
Dictating the number of times to move the arrow keys?
« on: July 28, 2021, 07:40:44 PM »
Assume there's a tabletop game like Monopoly and I rolled a six going forward and two going left. Is there a command to start dictating the number of times to move the arrow keys?

"Down arrow 3 times" and "Left arrow 2 times" being able to be executed from the same command would be magnificent.

There is a plethora of commands that sail over my head even with the PDF document provided and I figure smarter heads can point me in the right direction.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Dictating the number of times to move the arrow keys?
« Reply #1 on: July 28, 2021, 08:23:42 PM »
Not quite clear what you mean by "from the same command", but one way to have a command press an arrow key a given number of times, would be to use dynamic command sections, a loop, and a few tokens, E.G.:
[left;right;up;down] arrow [1..6] times
Code: [Select]
Set text [~key] to '[ARROW{TXTSUBSTR:"{CMD}":0:1}]'
Start Loop : Repeat [{TXTNUM:"{CMD}"}] times
    Press variable key(s) [~key] and hold for 0,1 seconds and release
End Loop
you may need to add a short pause underneath the keypress action, if you find fewer presses than spoken are registering in your target application.

With a command like that, you'd speak something like "down arrow three times", after which the down arrow would be pressed three times, so you can then speak "left arrow two times", and the left arrow would be pressed two times.

DzedDonut

  • Newbie
  • *
  • Posts: 3
Re: Dictating the number of times to move the arrow keys?
« Reply #2 on: July 28, 2021, 11:26:54 PM »
Ah, that is exactly what I was intending to use, thank you.
It's you! You've been 98% of the answers I have found via Google searches that led to the Steam forums and here. Thanks for helping me and countless others with answers, Pfeil.

If I can pick your brain for another question-
Is there a way to simplify this command: " [Show; Display; Bring up] Map; Map [on; show; display] " by combining 'map' into one instance rather than two separated by ;?


Edit:
Pardon but how would I go about adding the code you shared in the answer? I'm poking around so I am bound to stumble upon the answer.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Dictating the number of times to move the arrow keys?
« Reply #3 on: July 29, 2021, 07:12:21 AM »
Is there a way to simplify this command: " [Show; Display; Bring up] Map; Map [on; show; display] " by combining 'map' into one instance rather than two separated by ;?
There is not, no. That is the correct way to define those phrases.

If you were to have [Show; Display; Bring up] Map [on; show; display] instead, you'd define a bunch of extra phrases you'd never speak (E.G. "show map show"), as you probably figured out already

There is currently no method for defining mutually exclusive phrase sections without repeating certain sections, as you have done.


how would I go about adding the code you shared in the answer?
As with any VoiceAttack command, you'll want to add the relevant actions to the action list. The code block shows what your action list would like like when you're done.

In this case, you'll want to add a "Set a Text Value" action, followed by a "Loop Start - Repeat a Certain Number of Times" action (which will automatically add a "Loop End" action), containing a keypress action set to use the "Variable Keypress (Advanced)" option.
The first two can be found in the "Advanced" section of the "Other >" menu


The documentation contains more information on the features used in this command; Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer.

These topics may also be of use, in addition to the official documentation:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

DzedDonut

  • Newbie
  • *
  • Posts: 3
Re: Dictating the number of times to move the arrow keys?
« Reply #4 on: July 29, 2021, 10:47:17 AM »
Argh. I've hit a bit of a dead end. I know " ARROWD - arrow down, ARROWL - arrow left, ARROWR - arrow right, ARROWU - arrow up " may play a role in the variable command but things are a few inches above my head in terms of comprehension, even with the links you provided.

The attached image is where I am at and the result is the message "10x Key press by variable [Press variable key(s) [~key] and hold for 0,1 seconds and release] not set. No keys pressed."

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Dictating the number of times to move the arrow keys?
« Reply #5 on: July 29, 2021, 11:01:18 AM »
What is in the "Code:" field is what you should have in your action list.

Part of what is shown is the action itself, but three of the four entries also show what would be in one of the fields of that action's configuration dialog.

What the example command would do, is set a text variable named "~key", to literal text that forms a variable hotkey indicator, E.G., as you mentioned "ARROWD".
It does this by using the "{TXTSUBSTR:}" token to get the first letter (starting at position 0, retrieving 1 character) of the phrase that was spoken to trigger the command, which is supplied by the "{CMD}" token.

As is mentioned in the second linked topic, tokens are replaced by literal text, and they can be used to partially or entirely substitute literal text.

This is used to combine the literal text "[ARROW", with the output of the tokens (E.G. "d"; variable hotkey indicators are not case-sensitive, so there's no need to convert to uppercase), followed by the literal text "]"

E.G. if you speak "down arrow 1 times", the contents of "~key" would be "[ARROWd]"


The keypress action should then retrieve the value of that text variable named "~key".