Show an AHK menu with submenu already open

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Show an AHK menu with submenu already open

30 Jun 2014, 20:44

I haven't found a post on this yet. How can I show an AHK menu with one of its submenu already open?

I tried this:

Code: Select all

Menu, MyMenu, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item1, MenuHandler
Menu, MyMenu, Add, &My Submenu, :Submenu1
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
Sending the menu shortcut does not work. The Send command is buffered and executed only when the menu is closed.

Is there another way to open a submenu before or after the Show command? I tried WinMenuSelectItem but can't find how to apply this to AHK menus.

Thanks!
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Show an AHK menu with submenu already open

30 Jun 2014, 21:48

guest3456 wrote:You sure its not Alt+M ?
Alt-x is used to open menus like &File (Alt-F), &Options (Alt-O).

With an AHK popup menu, typing "M" manually works. And when an AHK popup menu is displayed, pressing Alt closes it.
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Show an AHK menu with submenu already open

01 Jul 2014, 00:04

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
   }
}



:(

User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Show an AHK menu with submenu already open

01 Jul 2014, 15:35

Thanks for trying all this, guest3456.

Using your code, I played with various combination of SetTimer, Sleep, priority, etc. without more success.

Maybe, this is just not possible?
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 487
Joined: 29 Sep 2013, 21:29
Location: Montreal, Quebec, Canada
Contact:

Re: Show an AHK menu with submenu already open

01 Jul 2014, 17:25

trismarck wrote:See here.
Thanks for pointing this trismarck. To me, this closes the point. I can find another approach to what I want to achieve.

Thank you all !
:thumbup: Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Now working on Quick Clipboard Editor
:ugeek: The Automator's Courses on AutoHotkey

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 246 guests