[jawsscripts] Re: Passing Keystrokes to another application

  • From: Doug Lee <doug.lee@xxxxxxxxxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Fri, 24 Apr 2009 10:39:23 -0400

Beware:  I have been told that menu IDs can change in an application
update, much like control IDs can.  The technique is cool in that
it avoids a number of problems associated with sending keystrokes to
invoke menu items, but the scripts using this technique may need
updates when the application changes.

On Fri, Apr 24, 2009 at 10:32:48AM -0400, David Farough wrote:
Hi Don:
I'm glad that worked for you.  Yes the blink when the window gets focus
is unavoidable in this case.  It just occurs to me that you might have
another option.
if you do not already have a copy you should go to Jamal's site and
download WinDig.  If you are lucky maybe this program will be able to
provide you a menu id for each of these commands.  If so, you could use
the SendMessage function to perform the commands you want.  You would
pass the handle of the main window and the menu id of the command in
question.  If you can retrieve the necessary menu IDs for the commands
you are interested in, you would not actually have to change the focus
before performing this functionality. 
you can download windig from: 
http://www.empowermentzone.com/wdsetup.exe 

I will include below a post that Jamal sent to the list some time ago
which describes this technique.

In the "Menus" section of WinDig output, the last piece of data on the
line for a menu item is its menu ID--if one exists.  If a menu item
does
not have a hot key but does have a menu ID, you can create a hot key
via a
JAWS script and the SendMessage function.  For example, the following
line
of WinDig output is about the Paste Special menu item of WordPad:

2.5     Paste Special...        S       57639

The 2.5 number is the outline number of the menu hierarchy, indicating
that the menu item is the fifth one down the second menu, the Edit
menu.
The ... ellipses indicate that the menu item presents a dialog.  S is
the
access letter, indicating that you can press it when the Edit menu is
dropped down to invoke this menu item.  Finally, the 57639 number is
the
menu ID, similar to a control ID.

This review of the WinDig output for WordPad showed no accelerator key
for
PasteSpecial but a menu ID was available.  I am not suggesting that
scripts are needed for every menu item without a hot key--this is just
to
illustrate the technique, and you would judge whether such a script
adds
significant value in the context of the application.

Although it is also possible to invoke a menu item by sending
keystrokes
to the application, that technique is less reliable because it is
affected
by the current keyboard focus.  It also tends to produce extra speech
which you may then need to silence with SpeechOff and Delay functions.

The SendMessage approach, on the other hand, does not actually
activate
and navigate the menus of the application's user interface.  It uses a
Windows message constant, WM_COMMAND, which is passed with a menu ID
to
the application window associated with the menu of interest.  The
relevant
window handle is usually the one returned by GetAppMainWindow, but the
InvokeMenuItem wrapper function below does not assume this in case you
wish to use another window, including a window of an application other
than the one with focus.

  The code below consists of a generic function called InvokeMenuItem,
and
a sample script called PasteSpecial, which might be attached to
Control+Shift+V. Note that a limitation of this approach is that it
only
works if the application implements standard menus of the Win32 API.
Unfortunately, many applications do not, such as those in the
Microsoft
Office suite.

Jamal


Int Function InvokeMenuItem(Handle h, Int i)
Var
Int WM_COMMAND

Let WM_COMMAND = 273
Return SendMessage(h, WM_COMMAND, i, 0)
EndFunction

Script PasteSpecial()
Var
Handle h,
Int i

Let h = GetAppMainWindow(GetFocus())
Let i = 57639 ; menu ID of Paste Special in WordPad

InvokeMenuItem(h, i)
EndScript



David Farough
Application Accessibility Coordinator/coordonateur de l'accessibilit? 
Information Technology Services Directorate /
Direction des services d'information technologiques
Public Service Commission / Commission de la fonction publique
Email / Courriel:  David.Farough@xxxxxxxxxxxxx
Tel. / T?l:    (613) 992-2779 

>>> "Donald Marang" <donald.marang@xxxxxxxxx> 09:29 pm Thursday, April
23, 2009 >>>
Thanks David,

Works great!  Of course the video screen blinks when setting the focus
to 
the full screen window behind the video window.  Perhaps, I can use
this 
trick on my Verizon application as well, where I have trouble reliably

switching back from the SignIn helper application.

Don Marang


__________?
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

-- 
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:doug.lee@xxxxxxxxxxxxxxxx  http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller
__________ 
Visit and contribute to The JAWS Script Repository http://jawsscripts.com

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: