/* This HotstringSubMenu.ahk file include techniques which: 1. Creates a top-level menu for a accessing multiple submenus. 2. Uses Arrays to create top-level menu and submenus. 3. Uses data bound to a function to pass menu actions. 4. Uses variadic function parameter to directly pass arrays. When implementing the arrays and functions in this file, you create arrays and menus which you can directly access. Rather than deleting and recreating menus each time it's called, the functions permanently set up each menu for calling with the Menu, MainMenu, Show command. The menus remain available in the background accessed either through a top-level main menu or directly via individual Hotstrings shown in the top-level menu for each submenu. */ ; This AutoExecute section defines sample arrays and launches the menu building HotstringMenuAutoExecute: Greetings := ["Hi!","Hello!","What's up?","How's it going?"] FractionsA := {⅒: "one-tenth",⅑: "one-ninth",⅛: "one-eight",⅐: "one-seventh",⅙: "one-sixth Brk" ,⅕: "one-fifth",¼: "one-fourth",⅓: "one-third Brk",⅜: "three-eights",⅖: "two-fifths" ,½: "one-half",⅗: "three-fifths",⅝: "five-eights",⅔: "two-thirds",¾: "three-fourths" ,⅘: "four-fifths",⅚: "five-sixths",⅞: "seven-eights"} ArrowsA := {⇐: "Left arrow",⇔: "Double arrow",⇒: "Right arrow" ,⇑: "Up arrow",⇓: "Down arrow"} Bovines := {🐂: "Ox",🐃: "Water Buffalo",🐄: "Cow",🐄🐂🐃: "All three!"} TopMenu := {FractionsA: "Fractions`tf``", ArrowsA: "Arrows`ta``", Bovines: "Bovines 🐂🐃🐄`tb``",Greetings: "Greetings`tg``"} TopMenu("MainMenu",TopMenu*) Return :x*:tp``::Menu, MainMenu, Show :x*:a``::Menu, ArrowsA, Show :x*:f``::Menu, FractionsA, Show :x*:b``::Menu, Bovines, Show :x*:g``::Menu, Greetings, Show TopMenu(MenuName,MenuItems*) { For Each, Item in MenuItems { HotstringMenuF(Each,%Each%*) Menu, %MenuName%, Add, % "&" A_Index " " Item, % ":" Each } } HotstringMenuF(MenuName,MenuArray*) { ArrayLength := MenuArray.SetCapacity(0) ; Get array size For Each, Item in MenuArray { If (ArrayLength < 10) Shortcut := "&" . A_Index Else Shortcut := "&" . Chr(A_Index+96) If (InStr(Item,"Brk")) ; Add column breaks to long menus { Item := StrReplace(Item,"Brk") Options := "+BarBreak" } Else Options := "" ; Bind output data to the InsertFunction() Handler := Func("InsertFunction").Bind(Each,Item) If (Each = A_index) ; Simple array Menu, % MenuName, Add, % Shortcut " — " Item, % Handler, % Options Else Menu, % MenuName, Add, % Shortcut " " Each " — " Item, % Handler, % Options } } InsertFunction(Key,Item) { If (Key ~= "^\d*$") SendInput {raw}%Item%%A_EndChar% Else SendInput {raw}%Key%%A_EndChar% }