A popup menu for Hotkey? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lennox
Posts: 7
Joined: 23 Apr 2022, 16:58

A popup menu for Hotkey?

Post by Lennox » 09 Feb 2023, 08:40

Hey guys!
I have on my computer several text editors and Internet browsers. I want to make a single or a couple of hotkeys to bring up some sort of popup menu or sth like windows context menu to choose one specific program among available ones. For instance, I program alt + ctrl + B to show a menu of installed internet browsers (currently I have Opera, Vivaldi, Edge, Brave and Firefox) and each time select the desired app and popup menu closes afterwards. Is there a way to this task?

gmoises
Posts: 75
Joined: 18 Nov 2017, 16:43

Re: A popup menu for Hotkey?

Post by gmoises » 09 Feb 2023, 12:06

For this example
have your icons in a subfolder named 'Icons'
with the same filename as the editor with extension '.png'
dimensions 16x16

If spaces are used in the Editor's name, use quotes

Code: Select all

#Requires AutoHotkey v1.1.36+

; the Hotkey
Hotkey, F5, Show, On

; create the menu
Menu:
	Editors  := {	Notepad:		"C:\Windows\System32\notepad.exe"
			  , 	TextPad:		A_ProgramFiles . "\TextPad 8\TextPad.exe"
			  , 	"Other 1":		A_ProgramFiles . "\Other 1\Other 1.exe"
			  , 	"Other 2":		A_ProgramFiles . "\Other 2\Other 2.exe"		}
	For Editor, Path in Editors
	{	Menu, List, Add		, %Editor%	, Run
		Menu, List, Icon	, %Editor%	, % A_ScriptDir . "\Icons\" . Editor . ".png"
	}
Return

; show the menu
Show:
	Menu, List, Show
Return

; open the selected editor
Run:
	Run, % Editors[A_ThisMenuItem]
Return

Lennox
Posts: 7
Joined: 23 Apr 2022, 16:58

Re: A popup menu for Hotkey?

Post by Lennox » 25 Feb 2023, 10:32

gmoises wrote:
09 Feb 2023, 12:06
For this example
have your icons in a subfolder named 'Icons'
with the same filename as the editor with extension '.png'
dimensions 16x16

If spaces are used in the Editor's name, use quotes

Code: Select all

#Requires AutoHotkey v1.1.36+

; the Hotkey
Hotkey, F5, Show, On

; create the menu
Menu:
	Editors  := {	Notepad:		"C:\Windows\System32\notepad.exe"
			  , 	TextPad:		A_ProgramFiles . "\TextPad 8\TextPad.exe"
			  , 	"Other 1":		A_ProgramFiles . "\Other 1\Other 1.exe"
			  , 	"Other 2":		A_ProgramFiles . "\Other 2\Other 2.exe"		}
	For Editor, Path in Editors
	{	Menu, List, Add		, %Editor%	, Run
		Menu, List, Icon	, %Editor%	, % A_ScriptDir . "\Icons\" . Editor . ".png"
	}
Return

; show the menu
Show:
	Menu, List, Show
Return

; open the selected editor
Run:
	Run, % Editors[A_ThisMenuItem]
Return
Hey there! Sorry for late response, sadly I was out of town. Can I change the background color of individual items in menu? like first one red, next blue and so on..

User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: A popup menu for Hotkey?  Topic is solved

Post by Hellbent » 25 Feb 2023, 15:44

Here is a very simple way to get a colorful context menu.

.
color menu.gif
color menu.gif (290.74 KiB) Viewed 625 times
.

Code: Select all

#SingleInstance, Force

MenuItems := []
MenuItems[ 1 ] := { Text: "Calculator" , RunPath: "Calc.exe" , TextColor: "White" , BackgroundColor: "Red" }
MenuItems[ 2 ] := { Text: "Item 2" , RunPath: "Calc.exe" , TextColor: "White" , BackgroundColor: "Green" }
MenuItems[ 3 ] := { Text: "Item 3" , RunPath: "Calc.exe" , TextColor: "000000" , BackgroundColor: "FFFFFF" }
MenuItems[ 4 ] := { Text: "Item 4" , RunPath: "Calc.exe" , TextColor: "ffff00" , BackgroundColor: "ff00ff" }
MenuItems[ 5 ] := { Text: "Item 5" , RunPath: "Calc.exe" , TextColor: "ffffff" , BackgroundColor: "0000ff" }

ControlHandles := []

Gui, 1:New, +AlwaysOnTop -Caption +Border +ToolWindow
Gui, 1:Color, 22262a
Gui, 1:Font, s16 Bold, Segoe UI
Gui, 1:Margin, 5, 5

Loop, % MenuItems.Length()	{
	cc := MenuItems[ A_Index ]
	Gui, 1:Add, Progress, % "w300 h30 +Disabled +Background" cc.BackgroundColor 
	Gui, 1:Add, Text, % "c" cc.TextColor " xp yp w300 h30  +BackgroundTrans +Center +0x200 hwndhwnd gRunIt" , % cc.Text
	cc.Hwnd := hwnd
	ControlHandles[ hwnd ] := cc
}
;~ gui, 1:Show


return
*ESC::ExitApp

F1::
	CoordMode, Mouse, Screen
	MouseGetPos, x , y
	Gui, 1:Show, % "x" x - 100 " y" y - 20
	return

RunIt:
	MouseGetPos,,,, ctrl, 2
	try{
		Run, % ControlHandles[ ctrl ].RunPath
	}catch{
		MsgBox, ERROR
	}
	Gui, 1:Hide
	return

It is also possible to create more complex designs.
.
color menu 2.gif
color menu 2.gif (356.23 KiB) Viewed 613 times

User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: A popup menu for Hotkey?

Post by Hellbent » 25 Feb 2023, 16:54

If a simple icon menu will do, you can also try this.

Image

viewtopic.php?f=6&t=102507&p=457282#p457109

Post Reply

Return to “Ask for Help (v1)”