I was helping someone in an AutoHotkey Facebook group this morning. The original request was how to have a HotString without requiring an ending character (tab, space, return, etc.). This is solved by simply putting an asterisk in between the first two colons.
i.e. :*:jg::Joe@the-Automator.com
However someone else mentioned a function they use to display a list of items and select from them. He didn’t share his function but I found something similar on the AutoHotkey forum. The example used the “Loop” and StringSplit commands. I decided to adapt it to use a for Loop and StrSplit function.
HotString to bring up a GUI with multiple text selections in AutoHotkey
Here’s the code to use a HotString to bring up a GUI with multiple text selections in AutoHotkey
#SingleInstance,Force ;make sure it only runs once
:*:jg::Joe@the-Automator.com ;This does solve initial request
:*:gg:: ;when I type gg bring up the menu (* means don't wait for an end charachter)
TextMenu("This is, cool¦But I like¦to do more¦with these¦But that's about`n`nit")
return
:*:ff:: ;when I type gg bring up the menu (* means don't wait for an end charachter)
TextMenu("this¦is from the ¦ff choice I typed¦Pretty cool¦huh")
return
TextMenu(TextOptions){
for k, MenuItems in StrSplit(TextOptions,"¦") ;parse the data on the weird pipe charachter
Menu, MyMenu,Add,% MenuItems,Action ;Add each item to the Menu
Menu, MyMenu, Show ;Display the GUI and wait for action
Menu, MyMenu, DeleteAll ;Delete all the menu items
}
Action:
ClipboardBackup:=ClipboardAll ;backup clipboard
Clipboard:=A_ThisMenuItem ;Shove what was selected into the clipboard
Send, ^v ;paste the text
sleep, 50 ;Remember to sleep before restoring clipboard or it will fail
Clipboard:=ClipboardBackup ;Restore clipboard
return