[jawsscripts] Re: Searching menu structures for a particular menu item

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Wed, 24 Dec 2008 10:05:33 -0500 (EST)

I found a message I previously wrote explaining the SendMessage (or
PostMessage) technique for invoking a menu item.  Once again, WinDig is
available at
http://EmpowermentZone.com/wdsetup.exe

You can get almost any of my programs from the Open Source Projects page
of
http://NonvisualDevelopment.org

Jamal

From: Jawsscripts-bounces@xxxxxxxxxxxxxxxxxxxx on behalf of Jamal Mazrui
[empower@xxxxxxxxx]
Sent: Friday, September 23, 2005 6:36 AM
To: jawsscripts@xxxxxxxxxxxxxxxxxxxx
Subject: Using WinDig output to invoke menu choices via SendMessage

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


_____________________________________________________________

To leave this list, send a blank message to
jawsscripts-unsubscribe@xxxxxxxxxxxxxxxxxxxxx
Information about all of our lists:
http://blindprogramming.com/mailman/listinfo
Other blindness lists:
http://www.visionrx.com/library/resources/resource_int1.asp
Web site address: http://www.BlindProgramming.com


_______________________________________________
Jawsscripts mailing list
Jawsscripts@xxxxxxxxxxxxxxxxxxxx
http://blindprogramming.com/mailman/listinfo/jawsscripts_blindprogramming.com

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

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

Other related posts: