13 August 2011. Alasdair King.
Thunder has a powerful scripting mechanism, allowing you to tailor hotkeys and speech output to particular applications.
There are built-in Thunder scripting features, and there are additional Thunder scripting features provided by AccessScripting. The latter are only available for installed versions of Thunder. Built-in features are available for both installed and USB memory stick versions of Thunder.
Thunder scripts are written in VBScript. The script must have the same name as the program it is being used for but with the extension ".lsc". So, for example, the Windows calculator (calc.exe) has the script calc.lsc. The script is placed in the Thunder program folder.
Start the Thunder script debugging window by starting Thunder and pressing the "+" key. This will let you see what is running and usable. You can write to the Script Debugging List in your script by calling ScriptDebug with a string. Make sure it's a string by appending & " " (that's ampersand, quotation marks, space, quotation marks).
You may find it easier to copy the Thunder folder out of Program Files into your Documents folder and work on the scripts there, so you donít have to be an administrator or turn off UAC to edit the scripts. Thunder will work fine there.
To start scripting for Thunder you are probably best to start looking at some existing scripts. Try calc.lsc first and then Excel.lsc - they should get you going.
The last string that was spoken by the speech synthesizer.
RectTop, RectBottom, RectLeft, RectRight
Integer values populated by the Rectangle functions. Call the appropriate function before using them.
Resolution of the whole screen. Like every other x, y value, measured in pixels.
Populated by CursorPos and ReadingPos, giving you the location of the screen cursor (mouse pointer) and Thunder reading cursor respectively.
Corresponds to the novice mode setting in Thunder settings. Adds extra explanatory text to speech output for new users.
Corresponds to the Speak Home, End etc. setting in Thunder settings.
Corresponds to the Spell Numbers setting in Thunder settings.
If set/true then plays the tones as you cursor around the screen. Corresponds to the UseMusic setting in Thunder settings.
Stops all Midi interaction with Thunder to leave your application free to do its own music. (There's a Midi function in Thunder!)
When the Thunder reading cursor is moved by a hot key it moves either by 4 pixels (MoveBy = 0) or by object (MoveBy = 1) (Thunder versions before 1.0.46 moved by 7 pixels) Moving by object means that the cursor is moved until a new MSAA object is under the mouse (testing at 7 pixel intervals).
Corresponds to the "Echo characters" and "Echo words" checkboxes in Thunder settings. 0 is both off, 1 is characters only, 2 is words only, 3 is characters and words.
Corresponds to the Punctuation setting in Thunder settings. 0 is none, 1 is some and 2 is all.
If an application has an object model accessible through COM via CreateObject or GetObject then set this string to be the name of the object mode and then call ObjectInit. See Word and Excel scripts for examples.
The object created by ObjectInit, the scripting automation COM object for the object model for the application. Use automation objects for scripting complex applications like Word, Excel or IE.
Returns the position of the caret obtained from MSAA in pixels. This is generally the position of the flashing caret in text areas, and is not the same as the screen cursor (mouse pointer) or the Thunder reading cursor.
If true then MSAA detected a caret change - the user typed something or cursored around a text field.
If true then MSAA detected a menu opening/closing/changing.
If true then MSAA has detected a change in focus or another MSAA event.
Use this to tell Thunder that the script has dealt with what needs to be spoken, and Thunder should not do any of its own speaking.
Sets ScriptObject to the automation scripting object indicated by ScriptObjectName. Set ScriptObjectName to the string for the automation interface (e.g. "Word.Application" for Microsoft Word) then call ObjectInit, and ScriptObject should now be the Word automation Application object. You must call this function before doing anything with ScriptObject, and call it in every function - you cannot assume that ScriptObject will persist.
Sets ScriptObject to Nothing.
Returns the window handle (a long value) for the top-level application window indicated by x, y.
Returns the top coordinate of the current MSAA object window.
Returns the left coordinate of the current MSAA object window.
ScriptDebug(s as String)
Adds s to the Script Debugging List control in the Thunder debug window. Open the debug window by pressing "+" in Thunder.
Populates ScriptX and ScriptY with the position of the screen cursor (mouse pointer). Has the side effect of
Populates ScriptX and ScriptY with the position of the Thunder reading pointer.
Sets the position of screen cursor (mouse pointer).
Sets the position of the reading cursor and also the screen cursor (mouse pointer). Does not validate x and y values, just applies them. Use MoveReadingCursorAbsolute, it's safer.
Sets the position of the reading cursor but does not move the screen cursor (mouse pointer). Does not validate x and y values, just applies them.
As SetReadingCursor, but the change of position is relative to current position of the reading cursor. The screen cursor (mouse pointer) is moved to the same place as the reading cursor. x and y are clipped to the screen.
As SetReadingCursorQuiet but the x and y values are clipped to the screen.
Moves along spelling in Word to the next error.
Has something to do with stopping automatic reading in response to key events (not understood).
Returns (as a string, strangely) whether s is the same as the ClassName of the current window.
Load VBScript script with path s (not name s, I think.) Fires the InitialiseScipt event.
Load configuration of hot keys, speed etc., for configuration file with name s (not path s, I think)
Turns on the script timer. The EventTimer event will now fire every TimerInterval milliseconds until TimerDisable is called.
Turns off the script timer. The EventTimer event will no longer fire.
Set the speed (in ms) of the script timer, that is, the period with which EventTimer will fire. The default is 100ms.
Runs the program whose path is specified in string s.
Get input from user. This displays an input box with the appropriate strings as prompt and title, and returns the value provided by the user.
Displays Thunder's spell checking Window for MS Word.
Moves the foreground window to the top-left-hand corner of the screen and, if possible, maximises it
Speak string s.
Add string s to the speech buffer, but don't cancel previous messages.
Shut up the synthesiser.
Sets RectLeft, RectTop, RectBottom and RectRight with the application top-level window rectangle (the one with the parent of Desktop) that contains the window corresponding to x and y. Has the side effect of setting the Thunder ReadingRectangle to the top-level window rectangle.
Uses WindowFromPoint to get the Windows window containing x,y and sets RectLeft, RectTop, RectBottom and RectRight to its values. Has the side effect of setting the Thunder ReadingRectangle to the same Windows window.
Returns a string for the MSAA object at point x, y. This is formatted and suitable for presentation to the end-user. For example, an input button with the caption "Cancel" will return "Cancel button".
Returns the MSAA accName value for the MSAA object at x, y - but only the last line of it.
Sets ReadingRectangle to the Windows window containing x, y, but does not change RectLeft, RectTop, RectBottom or RectRight.
Returns the MSAA accName value, or if an empty string the accValue value, for the MSAA object at x, y.
Returns the MSAA accValue value for the MSAA object at x, y.
Sets RectLeft, RectRight, RectTop and RectBottom with the co-ordinates of the current foreground window. Has the side-effect of setting the Thunder ReadingRectangle to the current foreground window.
Returns string containing the window title of the current foreground window (using GetWindowText API call)
Clicks the left mouse button
Clicks the right mouse button
Presses the left mouse button down
Lifts the left mouse button up
Reduces the synthesizer voice speed by 1.
Increases the synthesizer voice speed by 1.
Return string s as string with characters separated by spaces
As Spell, but speaks with larger pauses between characters.
Repeat last speech message and spell it out.
Return string s as string with characters spelled out phonetically.
Repeat last speech message phonetically
SetMarker (i, x, y)
The marker i, which must be an integer between 1 and 255 inclusive, now has the values x and y.
Returns the x coordinate for the marker indicated by i.
Returns the y coordinate for the marker indicated by i.
Turns synthesizer off until VoiceOn is called or until user presses hot key.
Turn voice back on after a VoiceOff command.
Send the keystrokes specified by the string s to the current application. (Format is VB SendKeys codes)
Returns the text in the clipboard
Calls DoEvents, which lets the operating system handle other events in the queue. Useful if things are getting hung up, but can cause terrible confusion with the sequence of functions and events, so use with caution.
Returns the ith item from ScriptList. Not populated, do not use.
Returns the number of items in the ScriptList. Not populated, do not use.
There are three functions that deal with the Thunder instruction queue. This is a queue of instructions that you can add to. Instructions are excecuted every 20th of a second and then deleted. It can be useful for timing operations like ScriptSendKeys or mouse movements and clicks.
Adds instruction string s to the queue. An instruction string is a VBScript command.
Returns how many instructions are currently in the queue.
Clears the queue.
This event is fired when the script is first loaded.
This event is fired when the current script is about to be unloaded.
This event is fired when the user presses keys - it gives you the scancode and shift states. (Good example - see calculator script.)
This event fires on printable characters being typed. The character is passed in ch. (Good example - see calculator script.)
This event is fired when the user pressed one of the 10 script hot key combinations. The integer i indicates which one, from 1 to 10.
This event is fired when a new foreground window appears for the current application.
This event fires on the event timer. (See TimerEnable, TimerDisabled and TimerInterval above)
This event is fired when the user types a script string. The text is passed in s.
This event is fired repeatedly when the system is otherwise idle. This is how you access the MSAA and UI events in which you're interested, like the user tabbing around to a new control. When this is fired, check the values of GotCaretChange, GotMenu and GotMSAAchange. Note that these are not mutually exclusive.
This event is fired when the user presses the Thunder Help key (should be CAPS-Shift-F1)
AccessScripting is a component that gives you more scripting power in Thunder by providing extra functions. It has been included in Thunder installers since 2009. However, since it is a COM component (e.g. a DLL) it is only available for installed versions of Thunder. Thunder on a USB memory stick will not be able to use AccessScripting functions.
AccessScripting allows you to call the Windows API for MSAA and other accessiblity information from VBScript. You can also include it as a reference in VB6 programs to provide a convenient way to call these functions. This document will assume you're using VBScript (i.e. that you're scripting the Thunder screenreader.)
The functions are all the standard Microsoft functions, so their purpose and operation is not detailed here. Look at MSDN. Some of them are amended for operation from VB Script.
There are two VB Script files in this distribution: check those out for examples of how to use the DLL. They are CurrentWindowTitle.vbs and WhatIsAtPosition.vbs.
You must register AccessScripting.dll using regsvr32 or use Windows installer to make the appropriate registry entries. If youíve installed Thunder then you will have AccessScripting installed.
Set acc = CreateObject("AccessScripting.AccessObj")
You can then use the AccessObj functions detailed below. Most wrap the usual Windows API function with the same name, like GetForegroundWindow: it returns the window handle using the GetForegroundWindow API call and returns you the value. However, because VBScript is not strongly typed, any function that takes arguments, like AccessibleObjectFromWindow, can't use the usual declaration. For these functions I have provided a "VBS" version, which will work slightly differently from the API norm.
Some of these work fine from VB Script as-is. The exceptions have VBScript versions, see below.
Where a VBScript version exists, it has the same name as the normal API function with the three letters VBS appended to it. Some of the arguments are different, however.
Returns the IAccessible object (if available) from the point provided in x and y. There is no way to get the child variant at present.
Returns the IAccessible object (if available) from the window provided in hWnd. There is no way to get the child variant at present.
FindWindowExVBS (hwndParent, hwndChildAfter, lpszClass, lpszWindow)
Returns the ClassName (e.g. "Notepad" for notepad.exe) specified by the window handle.
PostMessageVBS (hWnd, wMsg, wParam, lParam)
SendMessageVBS (hWnd, wMsg, wParam, lParam)
There is one non-Windows function to help with debugging:
Writes string s to a text file on your desktop called accessscript.log. Creates if necessary, appends otherwise.