I have been playing around with non-standard menus a little bit, to see how reliably you can identify them and then make a script for them by using the code above. Especially since a lot more programs are non-standard on Windows these days, due to the influence of tools from the Linux world or different programming languages. You could tweak WindowSpy.ahk, but the above script is more simplistic and arguably easier to tweak for a specific purpose.
When we use WinMenuSelectItem or ControlSend, let's consider what's in them.
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinMenuSelectItem, WinTitle, WinText, Menu [, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6, ExcludeTitle, ExcludeText]
For the most part, you are putting in the
window title and then the
control info or having the
menu to act upon identified for you. When encountering a non-standard Windows menu, we can get class name or ahk_id with our limited Window info script or by putting the commands into the automating script itself to get this information, before doing some action.
I decided to pick on Open Office, because it uses a non-standard GUI and menu.
WinGet will give us the ID info, so that we can figure out the class name. With Open Office it's SALFRAME, and if you open up submenus, it will change to SALTMPSUBFRAME. You can also use the info from ahk_id or the ID variable as well to more clearly identify windows, menus, and submenus. For instance you will get #32768 for the class name with the submenu of standard windows.
The combination of class and title allows us to be quite confident we are acting upon the correct Window. We can use
AND (to include OR or NOT) to keep adding conditions and variables that must be correct, before using SEND. This simplistic method will be just about as reliable as ControlSend or WinMenuSelectItem and make it pretty easy to whip up a script for automating non-standard menus. Note- Shortcut keys or using the keyboard will tend to be more reliable than MouseClicks, but maybe not by much. When using class names and adding other variables (like height and width of the menu and submenu window), MouseClicks are quite accurate too.
This simple solution can have a hotkey above to active it or it can be under a label in your script and called by Gosub (
Gosub, Label).
Code: Select all
WinGet, ID, ID, A
WinGetTitle, title, ahk_id %ID%
WinGetClass, class, ahk_id %ID%
If WinActive("ahk_class" . "SALFRAME") AND InStr(title,"OpenOffice Calc")
{
Send, ^p ; opens print window
WinWait, Print ; title of print window
WinActivate, Print
Send, !{f4}
}
Or open properties with just keyboard input
Code: Select all
WinGet, ID, ID, A
WinGetTitle, title, ahk_id %ID%
WinGetClass, class, ahk_id %ID%
If WinActive("ahk_class" . "SALFRAME") AND InStr(title,"OpenOffice Calc")
{
Send, {RALT} ; the ALT tends to activate most menus
Send, {Down 14}
Send, {Enter} ; opens the Properties window or use the Send, !{i}
}