The Virtual Viewer

In previous versions of JAWS, the virtual viewer was only used in applications such as Internet Explorer and Microsoft Outlook Express. When you pressed JAWSKEY + H to review the list of JAWS hot keys for a given application, the keystrokes were spoken and you had no way of reviewing the list without pressing JAWSKEY + H a second time. This functionality, at times, made it difficult to get the desired hot key for the application.

JAWS now displays all help messages such as those created for the hot key help script performed by pressing JAWSKEY + H, the JAWSKEY + W, and JAWSKEY + F1 in the virtual viewer. When JAWS displays the information in the virtual viewer, the virtual cursor is active. You can use the normal navigation keystrokes to read, select, and copy the selected text to your favorite text editor.

You can use this same functionality in your scripts to display help information. From a script development standpoint, the virtual viewer is a Virtual Buffer created using the JAWS Scripting Language as the interface. The virtual viewer is also known as the user buffer.

The JAWS message format gives you greater flexibility when displaying text in the virtual viewer. You can format the text using spaces, carriage returns, tab stops, etc. After formatting your message, JAWS displays the text in the virtual viewer with the same look and feel as text found in a text editor or word processor. By default, JAWS displays all text in the virtual viewer in black on a white background (except for links). The text also has a font type of Arial, and a point size of 12.

Displaying Text in the Virtual Viewer

Before you display text in the virtual viewer, you should check the status of the virtual viewer to make sure it is not currently being displayed. You can use the built-in function, UserBufferIsActive, to check the status of the virtual viewer. The function returns a value of 1 when the virtual viewer is active or displayed and a value of 0 when the viewer is not being displayed. When the virtual viewer is active, you can use the built-in function, UserBufferDeactivate, to close the virtual viewer prior to redisplaying text. Deactivating the virtual viewer before JAWS displays new information prevents the user buffer text from running together.

The following code example illustrates the use of the UserBufferIsActive() and UserBufferDeactivate() functions. You should place these statements before the virtual viewer is activated by either the SayMessage or SayFormattedMessage functions.

If UserBufferIsActive () Then
    UserBufferDeactivate () ; closes the virtual viewer
EndIf

You can use either the SayMessage and SayFormattedMessage functions to display information in the virtual viewer. You pass the output type of OT_User_Buffer as the first parameter in either function to tell JAWS to display the message in the virtual viewer. Each function also accepts two additional parameters. The second parameter is the long message. This is the text of your message and can be in the form of a message contained in a message file, a string of text or a string variable containing the message. The third parameter contains the short message. Like the long message, the short message can be a message contained in a message file, a string of text or a string variable containing the message. If you are displaying information in the virtual viewer, JAWS ignores this parameter. Therefore, it is not necessary to pass any information in this parameter.

You can call either function using the following syntax:

SayMessage (OT_USER_BUFFER, "This text is being displayed in the virtual viewer")
; OR
SayFormattedMessage (OT_USER_BUFFER, "This text is being displayed in the virtual viewer.")

You can also create keystroke links in the virtual viewer by using the %KeyFor function. The %KeyFor function replaces the older use of the GetScriptKeyName function. Using the older method of speaking or displaying messages, you had to concatenate the string using the GetScriptKeyName function. Using the new message format, you can insert the script name directly into your message by adding the following line:

The percent sign preceding the function name acts as a placeholder for the keystroke. When the message is displayed in the virtual viewer, the function retrieves the keystroke for the script named in the functions parameter. The keystroke is displayed as a link that can be activated by pressing ENTER on the line containing the keystroke.

Inserting a space between the %KeyFor and the left parenthesis will display the keystroke as normal text and not as a link. :::

{#example-of-displaying-text-in-the-virtual-viewer} ### Example of Displaying Text in the Virtual Viewer :::

The following script and message file additions illustrate the use of the JAWS message format to display text in the virtual viewer:

::: {#test.jsm-1}

Test.jsm

:::

Const ; Strings For edit prompt:
    sDlgName = "Enter Name",
    sFirstPrompt = "First Name: ",
    sLastPrompt = "Last Name: "

Messages
; For msgHello, %1= the first name, %2 = The Last Name
@MsgHello
HELLO WORLD! My name is %1 %2.
Press, %KeyFor(HelloWorld), To redisplay this message.
Press ESCAPE To close this message.
@@
EndMessages

::: {#test.jss-1}

Test.jss

:::

Include "HjConst.jsh"; default constant definitions
Include "HjGlobal.jsh"; default global variable definitions
Include "common.jsm"; default virtual viewer constants and Messages
Include "test.jsm"; test message file

Script HelloWorld ()
Var
    String sFirstName,
    String sLastName,
    String sMessage
If UserBufferIsActive () Then; determine If user buffer is active
    UserBufferDeactivate (); close or deactivate the virtual buffer
EndIf
InputBox (sFirstPrompt, sDlgName, sFirstName) ; prompt For the first name
InputBox (sLastPrompt, sDlgName, sLastName) ; prompt For the last ;name
Let sMessage = FormatString (MsgHello, sFirstName, sLastName)
; replace the % place holders with data
SayFormattedMessage (OT_USER_BUFFER, sMessage) ; display the message in the user buffer
EndScript

In the above example, the script begins by checking the status of the virtual viewer. If the viewer is active, then JAWS deactivates it before the script continues processing. The two InputBox statements retrieve the first and last names from user input. The FormatString function then takes the first and last name information and combines it with the message to create a final version of the message. The message is then displayed in the virtual viewer using the SayFormattedMessage function.

If you create the script above, assign it to CONTROL + 1 and you enter "John" for the first name and "Doe" for the last name, JAWS displays the following text in the virtual viewer:

::: leftbar "HELLO WORLD! My name is John Doe. Press, CONTROL + 1, to redisplay this message. Press ESCAPE to close this message." :::

Using the Virtual Viewer Exercises

The following exercises give you practice creating and using messages in the virtual viewer. Before you start these exercises, make sure you have the Notepad.jss script file open within the Script Manager. This file should contain any practice scripts from earlier chapters of this manual. If you run Script Manager from within Notepad and a blank file is opened, type the following lines at the top of the file:

; Script file For Notepad
; JAWS version 12.0
Include "hjconst.jsh"
Include "common.jsm"

Displaying a Message in the Virtual Viewer

The objective of this exercise is to create a message and display it in the virtual viewer. You should start Notepad and run the Script Manager from within Notepad for this exercise. Before you write your script, you need to create the message used by your script in the Notepad.jsm message file. You can open the file within the Script Manager and add your message. If you already have a Notepad.jsm message file, do the following to open the file in the Script Manager:

  1. Press CONTROL + O to display the Open File dialog.

  2. Type Notepad.jsm in the File Name edit box and press ENTER.

  3. If you have not previously created the Notepad message file, perform the following:

    1. Press CONTROL + N to display the New File dialog.

    2. The active control is a list of file types. Press M. to select Messages followed by ENTER. This will open an untitled message file in the Script Manager.

    3. Type the following text in the file:

      ; Message file For Notepad
      Messages
      EndMessages
      
  4. Press CONTROL + S to save the file. JAWS prompts you for the filename. Type Notepad in the File Name Edit box followed by ENTER.

Now you are ready to insert the individual message in the Notepad.jsm message file. To add the individual message, perform the following:

  1. Press UP ARROW until you reach the line entitled "Messages."

  2. Press END. to move to the end of the line.

  3. Press ENTER twice to create two blank lines.

  4. Type the following message:

    @MsgVirtualViewer
    This text is being displayed in the virtual viewer. You can Use the virtual viewer To display helpful Messages and other information.
    Press ESCAPE. To close this message.
    @@
    
  5. Press CONTROL + S to save the file.

  6. Press CONTROL + TAB to move back to the Notepad.jss script source file.

    After you have moved back to the Notepad.jss script file, be sure to include the Notepad.jsm file. Failure to do so will result in errors at the time of compilation. For more information on the include statement see 5.0 Creating Scripts.

After you have added the message to the Notepad.jsm message file, you are ready to create the script. Your script should begin by determining if the virtual viewer is currently being displayed. If it is, then use the UserBufferDeactivate function to close the viewer before displaying the new message. After you have determined if the viewer is active and closed it if necessary, you should use the SayFormattedMessage function to display the message in the virtual viewer.

DisplayVirtualViewer Script Documentation:

  1. Script Name: DisplayVirtualViewer

  2. Can be Attached to Key: checked

  3. Synopsis: Displays a message in the virtual viewer.

  4. Description: Displays a message in the virtual viewer using the SayFormattedMessage function.

  5. Category: None

  6. Assign to: CONTROL + SHIFT + V


Script DisplayVirtualViewer ()
If UserBufferIsActive () Then
    UserBufferDeactivate ()
EndIf
SayFormattedMessage (OT_USER_BUFFER, MsgVirtualViewer)
EndScript

Additional Practice: Display context-sensitive help in the virtual viewer based on the active control (for example, edit field vs. button). What heuristics or APIs would you use to choose and update the content?

Displaying Keystrokes in the Virtual Viewer

The objective of this exercise is to take the previous exercise and add a keystroke link to the message JAWS displays in the virtual viewer. To add a keystroke to the message, you need only modify the message, save the message file and recompile the Notepad.jss script file. Start by performing the following steps to modify the message from the previous exercise:

  1. Press CONTROL + TAB until you reach the Notepad.jsm file.

  2. Press CONTROL + END to move the Insertion point to the bottom of the file.

  3. Press UP ARROW until you reach the line containing the text of "Press ESCAPE. to close this message."

  4. Press HOME. to move to the beginning of the line followed by ENTER twice. This will insert two blank lines above the current line of text.

  5. Press UP ARROW to move to one of the blank lines.

  6. Type the following text on this line:

    Press %KeyFor(DisplayVirtualViewer) To redisplay this message
    
  7. Follow this text by pressing ENTER twice.

  8. After you complete the above steps, your message should look like the following:

    @MsgVirtualViewer
    This text is being displayed in the virtual viewer. You can Use the virtual viewer To display helpful Messages and other information.
    Press %KeyFor(DisplayVirtualViewer) To redisplay this message.
    Press ESCAPE. To close this message.
    @@
    
  9. After you have modified the individual message, press CONTROL + S to save the message file. You then need to recompile the Notepad script file.

When you receive the "compile complete" message, you can move back to Notepad. Test the script by pressing the keystroke to activate the script. Your message should be displayed in the virtual viewer. Use the arrow keys to move through the message. Did you hear JAWS speak the keystroke as a link? If so, then press ENTER on the link to redisplay the message. If not, then return to the Script Manager and make sure your message is identical to the message shown above.

Additional Practice: Add multiple keystroke links (for example, open settings, toggle verbosity, show help) and implement link activation handlers. How will you ensure the viewer content stays synchronized with actual key bindings?