Ah I see.
Well, I tried
WinMenuSelectItem but that seemed to only work on a GUI menu (probably hence the "Win" in the command name
). And even so, it only worked on an actual menu item. It wouldn't allow me to expand the submenu:
Code: Select all
Menu, MyMenu, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item1, MenuHandler
Menu, MyMenu, Add, &My Submenu, :Submenu1
Gui, Menu, MyMenu
Gui, Show, w200 h200
return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
#z::
WinMenuSelectItem, %A_ScriptName%,, My Submenu, Item1
return
Because you're right, the script stalls until the
Menu,, Show command returns a result. I tried to start a timer prior to showing the menu, but the timer thread just blocked until the menu was cleared. The timer still blocked even when trying to use the
Priority sub commands for each to make the menu a lower priority thread, which I would have thought would allow the Timer to interrupt it
Maybe you could respond to some
OnMessage when the menu appears like WM_COMMAND, I don't know
edit/
Just tried WM_COMMAND, no dice, see comments:
Code: Select all
Menu, MyMenu, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item1, MenuHandler
Menu, MyMenu, Add, &My Submenu, :Submenu1
OnMessage(0x111, "WM_COMMAND")
return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
#z::
Menu, MyMenu, Show ; i.e. press the Win-Z hotkey to show the menu.
;send, M ; DOES NOT WORK
return
WM_COMMAND(wParam, lParam, msg, hwnd)
{
;MsgBox, wParam=%wParam%`nlParam=%lParam%`nmsg=%msg%`nhwnd=%hwnd%
if (wParam = 16777217) ;// seems to be 16777217 on my machine, use msgbox above to confirm
{
;MsgBox, hi
;Send, M ;// doesn't work either, msgbox 'hi' seems to show before the menu is actually shown
}
}