Creating Scripts to Read Information from the Screen

Now you know about the four cursors, let's discuss reading information directly from the screen.

You may find a variety of reasons for moving a cursor around a given window. Some applications contain buttons that are only accessible with the mouse or JAWS Cursor. These buttons usually cannot be reached by pressing TAB or through the menu system. You may also encounter applications that place blocks of text in areas of the screen that can only be read using the JAWS Cursor or Invisible Cursor.

Before you create any script that moves a cursor to read information, you should determine the outcome of the script. If you are trying to activate a button within an application window, use cursor movement keystrokes to move the JAWS Cursor or Invisible Cursor to the button. You should keep track of each keystroke you press as you move the appropriate cursor. Each cursor movement command you use has an equivalent built-in function. For example, the built-in function, NextLine, acts just like pressing the DOWN ARROW from your keyboard. It moves the active cursor down one line.

Instead of pressing JAWSKEY + PAGE DOWN to read the bottom line of the screen, use cursor movement commands instead. You can use the JAWS cursor to accomplish this task by following the steps below:

  • Press NUMPAD MINUS (-) to activate the JAWS Cursor.

  • Press JAWSKEY + NUMPAD MINUS (-) to route the JAWS Cursor to the location of the PC Cursor.

  • Press PAGE DOWN to move the JAWS Cursor to the bottom of the window.

  • Press JAWSKEY + UP ARROW to read the current line.

Now you know the steps needed to move the JAWS Cursor to and read the contents of the bottom line of the window. You can take these steps and use built-in functions to accomplish the same task.

You also need to think about which cursor you will use to read or access the information. Are you going to need mouse commands? Or will you only need to read the information? Use the JAWS Cursor when you will need to perform mouse commands such as left or right mouse clicking. Use the Invisible Cursor when you need to read information but do not need to perform mouse commands. You also need to remember not to leave the wrong cursor active when your script finishes. If you are using the invisible cursor to read information on the screen, you don't want to leave that cursor active when your script finishes. Instead, you want to make sure the cursor, which was active before the script is executed, is again activated when the script finishes.

Moving Cursors

After you activate a cursor you should save its location. This ensures that the cursor is restored to the correct position on the screen after your script is executed. For example, when you are using the JAWS Cursor to access a specific button within an application, you want it to stay there because you need to perform a left mouse click. If you write a script that moves the JAWS Cursor without saving it first, then you must move the JAWS Cursor back to the button after your script is finished. Failing to do this within your script results in the wrong cursor activated and in the wrong place.

When you have chosen to use either the JAWS Cursor or Invisible Cursor, you also need to move the cursor to the active application window. This action ensures the cursor you are using to read specific information is in the correct window. This is important as the JAWS Cursor and Invisible Cursor can be anywhere on your screen. So it is always a good idea to move these cursors to the active application. Otherwise, moving the cursor may yield unexpected results.

Saving the Cursor

You use the SaveCursor () built-in function to save the cursor and its location. The SaveCursor () function notes the active cursor and its present location. You can call this function after activating any of the cursors such as the JAWS Cursor. The following block of code illustrates the use of the SaveCursor () function:

JAWSCursor () ; activate the JAWS Cursor
SaveCursor () ; save the JAWS Cursor and its location

You can call the SaveCursor function multiple times in a script, after each cursor you activate. This is called "stacking saved cursors." The following code example illustrates the use of multiple SaveCursor () function calls:

JAWSCursor () ; activate the JAWS Cursor
SaveCursor () ; save the JAWS Cursor and its location
InvisibleCursor () ; activate the Invisible Cursor
SaveCursor () ; save the Invisible Cursor and its location

::: {#restoring-saved-cursors}

Restoring Saved Cursors

:::

After you perform your script and JAWS finds one or more saved cursors, JAWS restores them automatically. When you save multiple cursors, JAWS restores the cursors in reverse order.

You can also use the RestoreCursor () built-in function when you need to restore a specific cursor before your script finishes. This function is useful when you need to save a cursor first, perform an action with that cursor, and restore it before the script finishes.

The following code example illustrates the use of the RestoreCursor () function:

PCCursor () ; activate the PC Cursor
SaveCursor () ; save the PC Cursor
JAWSCursor () ; activate the JAWS Cursor
SaveCursor () ; save the JAWS Cursor
; reading statements go here
RestoreCursor () ; restore the JAWS Cursor

In the above example, the RestoreCursor () function restores the last saved cursor. In this case, the RestoreCursor () function restores the JAWS Cursor since it was the last cursor saved.

Routing the Cursors

The PC Cursor is generally the active cursor in most applications. When you need to access information outside of the boundaries of the PC Cursor, you need to route either the JAWS Cursor or Invisible Cursor to the location of the PC Cursor. When you route either cursor, you have a starting point that you know exists within the active application.

::: {#routing-the-jaws-cursor}

Routing the JAWS Cursor

:::

You use the built-in function, RouteJAWSToPC to move the JAWS Cursor to the location of the PC Cursor. This function repositions the JAWS Cursor to the exact position of the PC Cursor. This function also moves the mouse pointer to the location of the insertion point or selection highlight.

However, this function does not activate the JAWS Cursor. Any cursor movement functions used in your script will move the active cursor instead of the JAWS Cursor. If you want the JAWS Cursor to move you must activate it first. The following code example illustrates the use of the RouteJAWSToPC function:

JAWSCursor ()
SaveCursor ()
RouteJAWSToPC ()

In the above example, the JAWS Cursor is first activated and then saved. The RouteJAWSToPC function moves the JAWS Cursor from its current location to the location of the PC Cursor. At this point, you can use some of the cursor movement functions to move the JAWS Cursor.

::: {#routing-the-invisible-cursor}

Routing the Invisible Cursor

:::

You use the built-in function, RouteInvisibleToPC (), to move the invisible cursor to the location of the PC Cursor. This function repositions the Invisible Cursor to the exact position of the PC Cursor. Unlike the JAWS cursor, the Invisible Cursor is not connected to the mouse pointer, so the function does not move the mouse pointer.

If you want to move the Invisible Cursor you must also activate it first. The following code example illustrates the use of the RouteInvisibleToPC () function:

InvisibleCursor ()
SaveCursor ()
RouteInvisibleToPC ()

In the above example, the Invisible Cursor is activated then saved. The RouteInvisibleToPC () function then moves the Invisible Cursor to the exact location of the PC Cursor. Now that the Invisible Cursor is in the active window, you can use cursor movement commands to read information contained within the current application window.

Moving the Cursor

After you have activated, saved, and moved the JAWS Cursor or Invisible Cursor to the active application window, you can move the cursor. Nearly all of the keyboard commands you use to move the various cursors within JAWS have corresponding built-in functions. For example, pressing DOWN ARROW to move the cursor to the next line has a comparable built-in function of NextLine (). Likewise, pressing RIGHT ARROW has a comparable built-in function of NextCharacter.

When you press DOWN ARROW to read the next line, behind the scenes JAWS activates the SayNextLine () script. The SayNextLine () script does more than just move the cursor down to the next line. The script determines what type of window is active and then reads the information accordingly. :::

{#JAWSPageDown-and-JAWSPageUp} ### JAWSPageDown and JAWSPageUp {#JAWSPageDown-and-JAWSPageUp} :::

The JAWSPageDown and JAWSPageUp built-in functions perform special versions of their respective keyboard commands. You can use these functions when any of the cursors are active. However, the outcome of the function is based on the active cursor.

When the PC Cursor is active, each function performs the standard PAGE UP and PAGE DOWN commands for the application. For example, when you press PAGE DOWN from within a word processor, the PC Cursor is moved down a screen of information. Likewise, when you press PAGE UP from within a word processor, the PC Cursor is moved up one screen of information. The following code example illustrates the use of the JAWSPageDown () function using the PC Cursor:

PCCursor ()
SaveCursor ()
JAWSPageDown ()

In the above example, the PC Cursor is activated and then saved before it is moved. Next, the JAWSPageDown function moves the PC Cursor down one screen of information.

When the JAWS or Invisible Cursor is active, the JAWSPageDown () function moves the cursor to the bottom of the active window based on the cursor restriction setting. Likewise, the JAWSPageUp () function moves the JAWS or Invisible Cursor to the top of the active window based on the restriction setting. The following code example illustrates the use of the JAWSPageDown () function using the Invisible Cursor:

InvisibleCursor ()
SaveCursor ()
RouteInvisibleToPC ()
JAWSPageDown ()

In the above example, the Invisible Cursor is activated and then saved. Next, the RouteInvisibleToPC () function routes the Invisible Cursor to the location of the PC Cursor in the active window. Finally, the JAWSPageDown function moves the Invisible Cursor to the bottom of the active window.

The JAWS restriction setting is set to application by default. This setting keeps the JAWS Cursor and Invisible Cursor within the boundaries of the active application window. You can cycle through the various restriction settings by pressing JAWSKEY + R. See the JAWS help system for more information on cursor restriction settings. :::

{#jawsend-and-jawshome} ### JAWSEnd and JAWSHome :::

The JAWSEnd and JAWSHome built-in functions perform special versions of their respective keyboard commands. Like the JAWSPageDown () and JAWSPageUp () functions, you can use these functions when the PC Cursor, JAWS Cursor, or Invisible Cursor is active. However, the outcome of each function is based on the active cursor.

When the PC Cursor is active, each function performs the standard END and HOME commands for the application. For example, when you press END from within a word processor, the PC Cursor is moved to the end of the current line. Likewise, when you press HOME from within a word processor, the PC Cursor is moved to the beginning of the current line. The following code example illustrates the use of the JAWSHome () function using the PC Cursor:

PCCursor ()
SaveCursor ()
JAWSPageDown ()
JAWSHome ()

In the above example, the PC Cursor is activated, saved, and moved down one screen. The JAWSHome () function then moves the cursor to the beginning of the line. When you execute this block of code, the PC Cursor is limited to the active window.

When either the JAWS or Invisible Cursor is active, the JAWSEnd function moves the cursor to the last text character or graphic on the line within the active window. Likewise, the JAWSHome () function moves the cursor to the first text character or graphic on the current line within the active window. The active window is based on the cursor restriction setting. The following code example illustrates the use of the JAWSHome () function using the Invisible Cursor:

InvisibleCursor ()
SaveCursor ()
RouteInvisibleToPC ()
JAWSPageDown ()
JAWSHome ()

In the above example, the Invisible Cursor is activated, saved, moved to the location of the PC Cursor and moved to the bottom of the screen. Next, the JAWSHome () function moves the Invisible Cursor to the beginning of the current line. By moving the Invisible Cursor to the beginning of the current line, you now have a distinct starting point. You can then use a number of other built-in movement functions to move the Invisible cursor across the line to read a specific piece of information such as a line number.

::: {#next-and-prior-cursor-movement}

Next and Prior Cursor Movement

:::

You can also use built-in functions to move to the next or prior piece of information. Many of these functions also have equivalent keyboard commands like the JAWSEnd (), JAWSHome (), JAWSPageDown (), and JAWSPageUp () functions.

You can use these functions with any of the three cursors. However, the outcome of the function is determined by the active cursor. For example, if you move the JAWS Cursor to the title bar of the active application, you can continually press JAWSKEY + RIGHT ARROW to move across the title bar a word or graphic at a time. When you continually press this keystroke, the JAWS Cursor does not stop at the end of the line. Rather, it continues to move on to the next line until you reach the bottom of the window.

On the other hand, you can only move the PC Cursor within the document edit area of a word processor when you continually press JAWSKEY + RIGHT ARROW. Once you reach the bottom of the document edit window, the PC Cursor can move no further.

When you continually press JAWSKEY + RIGHT ARROW, JAWS activates the SayNextWord script. The script must determine how to read the next word based on the active window. When you use any of the built-in functions to move to the next item, the active cursor is only moved to that item, but, does not speak it. :::

The following list of built-in functions moves the active cursor based on the name of the function. For example, the NextWord() function moves the active cursor to the next word. The NextSentence function moves the active cursor to the next sentence and so on.

  • NextCharacter ()

  • NextLine ()

  • NextParagraph ()

  • NextSentence ()

  • NextWord ()

  • PriorCharacter ()

  • PriorLine ()

  • PriorParagraph ()

  • PriorSentence ()

  • PriorWord ()

The following code example illustrates the use of the NextWord function using the Invisible Cursor:

InvisibleCursor ()
SaveCursor ()
RouteInvisibleToPC ()
JAWSPageDown ()
JAWSHome ()
NextWord ()

In the above example, the Invisible Cursor is activated, saved, and then routed to the location of the PC Cursor. Next, the Invisible Cursor is moved to the bottom of the screen and then to the beginning of the current line. The NextWord function then moves the Invisible Cursor to the next word or graphic on that line.

Speaking the Information

As you learned in the previous section, the movement functions built into JAWS only move the cursor, but do not speak any information. You must use another built-in function to actually speak the information found at the active cursor location.

You can use built-in functions to read the current character, word, line, and more. You can also use built-in functions to read information from the cursor location to either the beginning of the line or the end of the line. You can use the functions listed below to read a specific piece of information. For example, the SayCharacter () function speaks the current character while the SayWord () function speaks the current word. The list of functions follows:

  • SayCharacter ()

  • SayChunk ()

  • SayField ()

  • SayLine ()

  • SayParagraph ()

  • SaySentence ()

  • SayWord ()

The functions listed below all speak information beginning at the location of the active cursor:

  • SayFromCursor ()

  • SayToCursor ()

  • SayToBottom ()

  • SayToPunctuation ()

.hint You can find more information for any of the functions listed above by reviewing the documentation file for functions built into JAWS, builtin.jsd. You can view this file in the Script Manager or in any text editor. You can find this file in the JAWS shared settings folder. Navigate to the JAWS program group in the Start menu and choose Explore JAWS Explore Shared Settings. This opens a Windows Explorer screen where you can find all of the original JAWS script files. :::

Reading Information with Scripts Exercises

These exercises give you some practice in creating scripts that read pieces of information.

Reading the Script Manager Status Line

The objective of this exercise is to use built-in cursor movement and reading functions to read the status line in the Script Manager.

  1. Press JAWSKEY + F2 to activate the Run JAWS Managers dialog.

  2. Press S to select the Script Manager followed by ENTER.

  3. Since this script should work in Script Manager, you need to open the script file for the manager. Choose Open Shared File from the File menu or press ALT + F followed by the letter E.

  4. Type the file name Script Manager and press ENTER. You don't need to include the file extension for script source files, .jss, because this is the default file type.

  5. Press CONTROL + END to move the insertion point to the bottom of the file. Press ENTER to create a blank line between the last script and your new script.

  6. Press CONTROL + E to activate the New Script dialog.

  7. Type "ReadBottomLine" in the Script Name edit box. Be sure to capitalize the first letter of each word in the name of the script.

  8. Press TAB to move to the Can be Attached to Key check box. Press SPACEBAR to check the check box.

  9. Press TAB to move to the Synopsis edit box. Type "Reads the status line in the Script Manager" without the quotation marks.

  10. Press TAB to move to the Description edit box. Type "Reads the status line in Script Manager using various cursor movement and reading functions" without the quotation marks.

  11. Press TAB to move to the Category edit combo box. You do not need to ENTER any information in this combo box as it is not used.

  12. Press TAB to the Assign to Key edit box. Press CONTROL + SHIFT + L. This is the keystroke that activates the script.

  13. Press ENTER to close the New Script dialog and return to the Script Manager window.

  14. Press UP ARROW once to move to the first blank line of the ReadBottomLine script.

  15. Press CONTROL + I to activate the InsertFunction dialog. You are looking for the function to save the current cursor. Type Save in the Function Name edit box. Did JAWS find the SaveCursor function? If so, then press ENTER to insert the function into your script and close the InsertFunction dialog.

  16. After you have inserted the SaveCursor function into your script, the insertion point is at the end of the line. Press ENTER to move to the next line.

  17. Press CONTROL + Ito activate the InsertFunction dialog. You now need to locate the InvisibleCursor function. This will activate the Invisible cursor which you will use to read the status line of the window. Find the InvisibleCursor function and press ENTER to insert it.

  18. Press ENTER to complete the line and move to a new blank line.

  19. Follow the same procedure found in step 17 to insert the following functions into your script: RouteInvisibleToPC JAWSPageDown SayLine

  20. After following these steps, the script should look like the following:

    Script ReadBottomLine ()
    SaveCursor ()
    InvisibleCursor ()
    SaveCursor ()
    RouteInvisibleToPC ()
    JAWSPageDown ()
    SayLine ()
    EndScript
    
  21. If your script looks like the one above, press CONTROL + S to save and compile the script file. Did you hear the compile complete message? If so, then you are ready to test the new script. If not, then go back to the script and make sure it looks like the one above then compile your script file a second time.

  22. Press CONTROL + SHIFT + L to test your script. Did you hear the status line of the Script Manager spoken by JAWS?

Additional Practice: Explore what other cursor movement and reading functions are available in the FSDN documentation. Create a script that reads a specific section of the Script Manager window, such as the script name list or the script body text. This will require you to understand window structure and cursor positioning, essential skills for advanced scripting.

Read the Line Number and Total Lines in the Script Manager Status Line

The objective of this exercise is to create a script that reads only the line number and total number of lines within the status line. In the previous exercise, you created a script that read the entire Script Manager status line. Create a script that only speaks the line number and total number of lines in the script file. On the script manager status line there is more information than you necessarily want to hear, for example, "For help, F1". Your script should only say what you want to hear, which is the word "line" followed by the total number of actual lines in the script file. If the Script Manager is not the active application, press ALT + TAB until the Script Manager becomes the active window. The Script Manager.jss script file should also be opened within the manager. You can verify the file name by reading the title of the window with JAWSKEY + T. Before you create the script, follow the steps below to determine what functions are needed:

  1. Press NUM PAD MINUS. twice in succession to activate the Invisible cursor.

  2. Press JAWSKEY + NUM PAD MINUS to route the Invisible cursor to the PC cursor location.

  3. Press PAGE DOWN. to move the Invisible cursor to the bottom of the window.

  4. Press HOME. to make sure the Invisible cursor is at the beginning of the status line.

  5. Press JAWSKEY + RIGHTARROW until JAWS speaks "Line:".

  6. Press JAWSKEY + PAGE UP to read from the location of the Invisible cursor to the end of the line.

After you followed the steps above, did JAWS speak the line number and total number of lines? Your new script should also read only the line number and total number of lines within the current script file. The steps needed to create the script follow:

  1. Press CONTROL + END to move to the bottom of the script file.

  2. Press ENTER twice to insert a blank line between the last script and your new script.

  3. Press CONTROL + E to activate the New Script dialog.

  4. Fill in the script information fields as follows:

    1. Script Name: ReadLineNumber

    2. Can be Attached to Key: checked

    3. Synopsis: Reads the line number and total number of lines.

    4. Description: Reads the line number and total number of lines from the status line.

    5. Category: not used

    6. Assign To: CONTROL + SHIFT + S

  5. After you have entered all the script information, press ENTER to close the New Script dialog and return to the Script Manager edit area.

  6. Press UP ARROW once to move to the first blank line in the body of the script.

  7. Use the InsertFunction dialog, activated by CONTROL + I, to insert the following functions into your script:

    1. SaveCursor ()

    2. InvisibleCursor ()

    3. SaveCursor ()

    4. RouteInvisibleToPC ()

    5. JAWSPageDown ()

    6. JAWSHome ()

    7. NextWord ()

    8. NextWord ()

    9. NextWord ()

    10. NextWord ()

    11. NextWord ()

    12. SayFromCursor ()

    You should press ENTER after each function is inserted into your script. Failure to do so, causes each of the functions to be inserted on the same line.

  8. After you have followed all the steps above, your script should look like the following:

    Script ReadLineNumber ()
    SaveCursor ()
    InvisibleCursor ()
    SaveCursor ()
    RouteInvisibleToPC ()
    JAWSPageDown ()
    JAWSHome ()
    NextWord ()
    NextWord ()
    NextWord ()
    NextWord ()
    NextWord ()
    SayFromCursor ()
    EndScript
    

After you have completed the steps above, Compare your script to the script shown above. Make any corrections to your script as necessary.

When correcting your script, you can use normal editing techniques just as you would in a word processor or text editor.

  1. Now that you have reviewed your script, press CONTROL + S to save and compile your script. Did you hear the compile complete message? If so, then you are ready to test your script. If not, then note the error shown in the Error dialog. Next, press ESCAPE. to close the Error dialog and return to your script. Review your script for the error and correct it. You can refer back to the script shown above, if necessary.

  2. Once you have a complete compile, press CONTROL + SHIFT + S to activate your script. Did you only hear the line number and total number of lines spoken by JAWS?

Additional Practice: Modify this script to read different portions of the Script Manager status line, such as the column number, word count, or other available information. Experiment with different combinations of cursor movement functions to extract and speak precise information. This demonstrates how scripting can provide customized access to application information.