Vocola Information Pages   by Rick Mohr   (last modified January 13, 2002)

 Introduction
 Using Vocola
 Language Tutorial
    Keystroke Commands
->     Using Alternatives
    Defining Variables
    Substituting Actions
    Function Calls
    Optional Words
    Comments
    Contextual Commands
    Example File
 Download Vocola
 Install Vocola
 Converting DVC Files
 Troubleshooting
 Support
 Wish List
 My RSI Story
 

Using Alternatives

Alternatives And References Sometimes you will want to create a group of similar commands. Instead of creating a separate command for each, you can often write a single command which works for the whole group.

For example, you might want to be able to say either "Switch View" or "Next View" to switch between views in an application:
 
 Vocola: (Switch | Next) View = {Ctrl+Tab}; 
 Say: Switch View  Sent: {Ctrl+Tab}
 Say: Next View    Sent: {Ctrl+Tab}

Here the alternative term (Switch | Next) allows you to say either.

In many cases you want the actions invoked by a command to depend on which alternative was spoken. For example, you might want to move the cursor in one of four directions by saying "Move Left", "Move Down", etc.:
 
 Vocola: Move (Left | Right | Up | Down) = {$1}; 
 Say: Move Left  Sent: {Left} 
 Say: Move Down  Sent: {Down} 

Here the reference "$1" specifies that the first variable term should be substituted. So, when you say "Move Left" the value of the first variable term is "Left" and the keystrokes "{Left}" are sent.
 
References may appear anywhere in a sequence of actions (i.e. on the right hand side of an "="), even inside quoted strings. If you want to insert the literal text "$1", use the escape sequence "\$1".

Often you will want to specify a range of numbers as alternatives in a command.  This can be specified concisely in Vocola, as in the following example:
 
 Vocola: Move Down 1..10 = "{Down $1}"; 
 Say: Move Down 1  Sent: {Down 1}
 Say: Move Down 6  Sent: {Down 6}

Here the syntax "1..10" is shorthand for "(1|2|3|4|5|6|7|8|9|10) ". On the right hand side we substitute the spoken number (e.g. "6 ") to construct the syntax for a repeated keystroke ("{Down 6}") and we have a command which moves the cursor down a specified number of lines.

In real life it's very useful to control the arrow keys by saying simply "1 Down", "3 Left", "6 Up", etc. Here's how to write it in Vocola:
 
 Vocola: 1..40 (Left | Right | Up | Down) = "{$2 $1}"; 
 Say: 3 Left   Sent: {Left 3}
 Say: 12 Down  Sent: {Down 12}

This command has two variable terms. On the right-hand side the second term (which direction to move) is substituted first and the first term (how many times) is substituted second, to create the necessary keystroke syntax.
 


This page is (c) Copyright 2002 by Rick Mohr, and was last modified on January 13, 2002.