Select menu items via keyboard

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
jfk4u
Posts: 1
Joined: 27 Mar 2023, 12:15

Select menu items via keyboard

Post by jfk4u » 27 Mar 2023, 12:32

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.

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

Re: Select menu items via keyboard

Post by mikeyww » 27 Mar 2023, 13:20

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.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Select menu items via keyboard

Post by flyingDman » 27 Mar 2023, 15:54

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
	}
14.3 & 1.3.7

WKen
Posts: 182
Joined: 21 Feb 2023, 00:01

Re: Select menu items via keyboard

Post by WKen » 28 Mar 2023, 00:01

You can also run multiple AHK files to pop up multiple menus.

Post Reply

Return to “Ask for Help (v2)”