# WinMenuSelectItem

Invokes a menu item from the menu bar of the specified window.

WinMenuSelectItem, WinTitle, WinText, Menu [, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6, ExcludeTitle, ExcludeText]

#### Parameters

WinTitle | The title or partial title of the target window (the matching behavior is determined by SetTitleMatchMode). If this and the other 3 window parameters are blank or omitted, the Last Found Window will be used. If this is the letter A and the other 3 window parameters are blank or omitted, the active window will be used. To use a window class, specify ahk_class ExactClassName (shown by Window Spy). To use a process identifier (PID), specify ahk_pid %VarContainingPID%. To use a window group, specify ahk_group GroupName. To use a window's unique ID number, specify ahk_id %VarContainingID%. The search can be narrowed by specifying multiple criteria. For example: My File.txt ahk_class Notepad
WinText | If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.
Menu | The name of the top-level menu, e.g. File, Edit, View. It can also be the position of the desired menu item by using 1& to represent the first menu, 2& the second, and so on.
SubMenu1 | The name of the menu item to select or its position (see above).
SubMenu2 | If SubMenu1 itself contains a menu, this is the name of the menu item inside, or its position.
SubMenu3 | Same as above.
SubMenu4 | Same as above.
SubMenu5 | Same as above.
SubMenu6 | Same as above.
ExcludeTitle | Windows whose titles include this value will not be considered.
ExcludeText | Windows whose text include this value will not be considered.

#### ErrorLevel

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

#### Remarks

For this command to work, the target window need not be active. However, some windows might need to be in a non-minimized state.

This command will not work with applications that use non-standard menu bars. Examples include Microsoft Outlook and Outlook Express, which use disguised toolbars for their menu bars. In these cases, consider using ControlSend or PostMessage , which should be able to interact with some of these non-standard menu bars.

The menu name parameters are not case sensitive (i.e. File->Save is the same as file->save) and the use of ampersand (&) to indicate the underlined letter in a menu item is not necessary (i.e. &File is the same as File).

The menu name parameters can also specify positions. This method exists to support menus that don't contain text (perhaps because they contain pictures of text rather than actual text). Position 1& is the first menu item (e.g. the File menu), position 2& is the second menu item (e.g. the Edit menu), and so on. Menu separator lines count as menu items for the purpose of determining the position of a menu item.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

#### Related

ControlSend, PostMessage

#### Example

    ; This will select File->Open in Notepad:
    WinMenuSelectItem, Untitled - Notepad, , File, Open

    ; Same as above except it's done by position vs. name:
    WinMenuSelectItem, Untitled - Notepad, , 1&, 2&