Page 1 of 1

Select menu items via keyboard

Posted: 27 Mar 2023, 12:32
by jfk4u
Hello,
I would like to write a menu with submenus.
The selection of the menu item should be done via the keyboard.
Example:
Menu: 1_Links , Submenu: 1_1_Internet_Links, 1_2_Server_Links.
Menu: 2_Outputs , Submenu: 2_1_Text_field1, 2_2_Text_field2

After calling the menu, I want to press a 2 on the numeric keypad to get to the menu item 2_Outputs and another 2 to get to the submenu item: 2_2_TextField2.

I want to create more than 100 menu items and there every keystroke is one too many if it can be avoided.

Re: Select menu items via keyboard

Posted: 27 Mar 2023, 13:20
by mikeyww
Welcome to this AutoHotkey forum!

The easy way is to prepend the menu text with your keyboard shortcut, such as 1-Item 1. Actually, that's the only way I know (perhaps aside from running a separate script), but others here may have some better tricks.

You could run a separate script just for handling the menu shortcuts.

Re: Select menu items via keyboard

Posted: 27 Mar 2023, 15:54
by flyingDman

Code: Select all

#Requires AutoHotkey v2.0

MyMenu := Menu()
	Submenu1 := Menu()
		SubSubmenu1 := Menu()
		SubSubMenu1.add "&1 Google 1_1_1", MenuHandler
		SubSubMenu1.add "&2 Bing 1_1_2", MenuHandler
	Submenu1.Add "&1 InternetLinks", SubSubMenu1
	Submenu1.Add "&2 ServerLinks 1_2", MenuHandler
MyMenu.Add "&1 Links ", Submenu1
	Submenu2 := Menu()
	Submenu2.Add "&1 Textfield1 2_1", MenuHandler
	Submenu2.Add "&2 Textfield2 2_2", MenuHandler
MyMenu.Add "&2 Outputs", Submenu2

F12::MyMenu.Show								                 ; launch the menu

MenuHandler(Item, *)
	{
    MsgBox(substr(Item,instr(Item," ")),"Menu","T2")             ; use switch
	}

Re: Select menu items via keyboard

Posted: 28 Mar 2023, 00:01
by WKen
You can also run multiple AHK files to pop up multiple menus.