Question about popup menu

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XMCQCX
Posts: 257
Joined: 14 Oct 2020, 23:44

Question about popup menu

Post by XMCQCX » 21 May 2021, 10:04

Hi, I'm trying to make a popup menu using the code in the examples.

Code: Select all

; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Add  ; Add a separator line.

; Create another menu destined to become a submenu of the above menu.
Menu, Submenu1, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item2, MenuHandler

; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
Menu, MyMenu, Add, My Submenu, :Submenu1

Menu, MyMenu, Add  ; Add a separator line below the submenu.
Menu, MyMenu, Add, Item3, MenuHandler  ; Add another menu item beneath the submenu.
return  ; End of script's auto-execute section.

MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return

MButton::Menu, MyMenu, Show
When the menu is open and you click the hotkey again at a new position, nothing happens. How to modify it to behave like window explorer context menu. When you click the hotkey again at a new position, the menu close and reopen at the new mouse position. I tried a few things, but I was not able to do it. Any help is appreciated

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Question about popup menu

Post by mikeyww » 21 May 2021, 11:07

My understanding is that an open menu essentially suspends the script until the menu is resolved. You might be able to set a timer to check conditions as a workaround, though it sounds clunky.

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: Question about popup menu

Post by WatsonEnterprises » 22 May 2021, 03:06

Instead of using ahk's Menu, you could design a custom GUI that resembles a menu. Unlike a menu, your script hotkeys would still respond while your GUI is open.

Or, you could run the menu as a separate script. Hotkeys from your main script will still respond, since it's not the one showing the menu.

Code: Select all

;MainScript.ahk
;"When you click the hotkey again at a new position, the menu close and reopen at the new mouse position."
F1::Run, % "MenuShower.ahk"

Code: Select all

;MenuShower.ahk
#SingleInstance, force

Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Show
return

MenuHandler(){
	MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
}

XMCQCX
Posts: 257
Joined: 14 Oct 2020, 23:44

Re: Question about popup menu

Post by XMCQCX » 22 May 2021, 05:38

WatsonEnterprises wrote:
22 May 2021, 03:06
Or, you could run the menu as a separate script. Hotkeys from your main script will still respond, since it's not the one showing the menu.
Thank you very much, WatsonEnterprises. It's working !

Post Reply

Return to “Ask for Help (v1)”