I always loved Stack Overflow, as you can find code snippits quickly to do different things. I thought it would be very helpful to have something similar for JAWS scripting. The below assumes you have an idea about scripting. If you don’t yet, that’s ok, start by browsing through the Basics Of Scripting guide from Freedom Scientific.
Setting focus to an application quickly.
This will take two different scripts or functions to make this happen.
The first will grab the window handle of the open application that you want to move back to quickly. You can set this up within an AutoStartEvent within the script file for the application, or, make two scripts that you can use for any single application.
Void Function AutoStartEvent ()
EndFunction
The above is an empty function, AutoStart event. Before you start, see if this exists already within your script file. If it’s there, you can add functions to it. Lets add a globals section above the AutoStartEvent. This will be for the variable to hold your window handle. It will look like
Globals
Handle AppFocus
The below will be what you would add into the AutoStartEvent
let AppFocus = GetCurrentWindow ()
let AppFocus = GetAppMainWindow (AppFocus)
AutostartEvent looks like
Void Function AutoStartEvent ()
let AppFocus = GetCurrentWindow ()
let AppFocus = GetAppMainWindow (AppFocus)
EndFunction
Now lets create a script within the default file which will link back to the AutoStartEvent within the app spisific file, and set the app to focus at the press of a keystroke.
Press control+shift+D to launch the default script file.
Press control+end to move to the end of the file, Make sure you are on a blank line.
Press, control+e to launch the new Script dialogue and give it a name.
tab to the checkbox for Can be attached to key and check it
tab to the comments sections and write what the script will be used for
as you come to the, assign to hotkey box, type a keystroke that will be used to run the script such as
control+alt+f
for example.
Tab to ok and press space.
Now you are in the script editor, make sure your curser is on the line below the script name.
Now you want to paste or type the following
SetFocus (AppFocus)
TypeKey (“Windows+UpArrow”)
Press control+s to save the script and verify compile complete
Now, move to the top of the script file with control+home.
JAWSFind
Use
f3 through the results until you start coming across
use “UIA.jsb”
use “HomeRowWindows.jsb”
use “HomeRowMSAA.jsb”
Down arrow until you know you are at the end of the use statements and press enter to have a blank line below the last one.
Type Use “MyApp.jsb”
where MyApp is the name of the script file you have motified the AutoStartEvent in.
Press control+s to save and compile again.
Now launch the app in question.
Minimise it with windows+m
press the keystroke you have assigned to pull it back in focus.
The app should now be in focus.
IF you are using the first in a script, vs AutoStartEvent in an app spisific file, you would create two scripts in the default file. The first will look like
Globals
Handle AppFocus
Script ()
let AppFocus = GetCurrentWindow ()
let AppFocus = GetAppMainWindow (AppFocus)
EndScript
using the same techniques above to create the script Control+e etc.
Then you will create the second script the same as
SetFocus (AppFocus)
TypeKey (“Windows+UpArrow”)
The first script will grab the focus of the app and you will only need to press it once, in less you close the app.
The second script will set focus back to the app.