Author Topic: Need help with a command  (Read 1294 times)

DustyB123

  • Newbie
  • *
  • Posts: 12
Need help with a command
« on: October 17, 2021, 07:45:27 PM »
I'm trying to make it so after I say "On" it makes it so that every time I press A, numpad 0 gets pressed then, there should be a 0.5 second pause, then numpad 5 gets pressed. If I say "off" it should stop the command.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #1 on: October 17, 2021, 10:53:57 PM »
Assuming you don't want the "A" keypress to get passed through, you'll need to use a command that triggers off of that key and has the "Do not allow key to be passed through" option enabled

So in total, you'd have three commands: One triggered by the "A" key, another for "On", and then the last one for "Off"

The latter two commands would just set a Boolean variable to either true or false.

The command triggered by the keypress would then check the value of that variable, and if it's true, perform the function you're describing, whereas if the variable value is not true, it'll instead press the "A" key using a keypress action.

To preserve the main functionality of the regular "A" key while the variable value is not true, you'd want to use a keypress action that presses the key, followed by a while loop that checks whether the key is still pressed, and then a keypress action that releases the key again.
Note that this will mean that holding down the "A" key does not produce multiple "a" characters, as virtual keypresses do not trigger that system.

DustyB123

  • Newbie
  • *
  • Posts: 12
Re: Need help with a command
« Reply #2 on: October 18, 2021, 03:02:31 PM »
I'm not really familiar with how to the use more advanced commands with variables, How do I do this properly?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #3 on: October 18, 2021, 04:19:45 PM »
These topics may be of use:
Control flow (If, Else, ElseIf, Loop, Jump) basics
Variables and tokens summed up

The official documentation goes into more detail on each of the actions you'll want to use; press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer, which contains information on VoiceAttack's features.


See what you can put together.

If it doesn't appear to work, right-click the action list of your command(s), choose "Copy All as Text" from the context menu, then paste here into a code block (click the # button)

DustyB123

  • Newbie
  • *
  • Posts: 12
Re: Need help with a command
« Reply #4 on: October 18, 2021, 09:20:51 PM »
The command seems to work but when I say "Off" and the condition is false, the "A" key doesn't press normally. How do I get the key to press when I hold down A?

Code: [Select]
Begin Boolean Compare : [A Key] Equals True
    Press B key and hold for 0.1 seconds and release
Else If Boolean Compare : [A Key] Equals False
    Press down A key
    Start Loop While :  Keyboard Key 'A' Is Pressed
        Release A key
    End Loop
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #5 on: October 18, 2021, 09:28:19 PM »
The action(s) within the loop are executed continuously as long as the loop runs, so the moment the loop starts, the key is released by the keypress action, which then also stops the loop as its condition (the key being pressed) no longer evaluates to "true".

Move the release keypress action to under the loop (which consists of two actions: a start, and an end). That way, the loop will run as long as the key has not been released, doing essentially nothing for that duration, and when the loop ends because the physical key is released, the virtual key will be released as well.

DustyB123

  • Newbie
  • *
  • Posts: 12
Re: Need help with a command
« Reply #6 on: October 18, 2021, 10:04:47 PM »
I moved it under the loop but it didn't work.

Code: [Select]
Begin Boolean Compare : [A Key] Equals True
    Press B key and hold for 0.1 seconds and release
Else If Boolean Compare : [A Key] Equals False
    Press down A key
    Start Loop While :  Keyboard Key 'A' Is Pressed
    End Loop
    Release A key
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #7 on: October 18, 2021, 10:10:46 PM »
If the value of the variable is false, the "A" key will function as it normally would, character repeat aside. If the value of the variable is true, as you have the command set up currently, the "B" key will be pressed, held for ~100ms, then released.

If you want to have the "A" key essentially act as if it were the "B" key, you'd need the same loop setup in that branch of the condition as well (replacing the "A" key with the "B" key in the keypress actions, but not in the loop)

DustyB123

  • Newbie
  • *
  • Posts: 12
Re: Need help with a command
« Reply #8 on: October 18, 2021, 10:31:36 PM »
I added the loop setup for "B" but now when the command is on "A" is still pressed and not "B". Should it go in a separate command?

Code: [Select]
Begin Boolean Compare : [A Key] Equals True
    Press down B key
    Start Loop While :  Keyboard Key 'B' Is Pressed
    End Loop
    Release B key
Else If Boolean Compare : [A Key] Equals False
    Press down A key
    Start Loop While :  Keyboard Key 'A' Is Pressed
    End Loop
    Release A key
End Condition

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #9 on: October 18, 2021, 10:37:24 PM »
As mentioned, the loop in the branch for the "B" key should still check whether the "A" key is pressed, as that is the physical key you're using to actuate the virtual key.

If "A" is being pressed, you either don't have the "Do not allow key to be passed through" option for the command enabled, or the value of the Boolean variable named "A Key" does not equal "true"

Assuming your "On" command sets the value of the "A Key" variable to "false", you'd want to use the "Off" command to set the variable value to "true" in order to have the "B" key pressed

DustyB123

  • Newbie
  • *
  • Posts: 12
Re: Need help with a command
« Reply #10 on: October 19, 2021, 04:44:14 PM »
Thanks for your help, I am disabled and have limited hand function and this command with help me a lot.

I'm not really sure what the problem with the command is, but is still not working properly.

What I want to happen is when I physically hold down the key (A when command is off or B when command is on) the virtual key should keep repeating until I let go of the physical key.

The first command is called “A Key”. It has voice disabled and is activated when I press A. “Do not allow key to be passed through” is checked. The rest of the command is:

Code: [Select]
Begin Boolean Compare : [A Key] Equals True
    Press down B key
    Start Loop While :  Keyboard Key 'A' Is Pressed
    End Loop
    Release B key
Else If Boolean Compare : [A Key] Equals False
    Press down A key
    Start Loop While :  Keyboard Key 'A' Is Pressed
    End Loop
    Release A key
End Condition

The second command is called “On” and is activated by saying “On”.

The other part of the command is:

Code: [Select]
Set Boolean [A Key] to True

The third command is call Off” and is activated by saying “Off”.

The other part of the command is:

Code: [Select]
Set Boolean [A Key] to False

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Need help with a command
« Reply #11 on: October 19, 2021, 05:00:12 PM »
If you want an action (or set of actions) to be repeated, that would go inside the loop, I.E. between the start and end actions.


If you don't see why the command is operating the way it currently is (which is exactly how you have configured it), perhaps it's worth having another look at Control flow (If, Else, ElseIf, Loop, Jump) basics