Update:
1. The menu can have both global items & dynamic entries that are based on active application.
2. Global items are sorted. Dynamic items appear at the bottom of menu (i figured this was most optimal)
3. Menu items can have spaces.
(instructions in script)
Run the script and press middle mouse button to show a menu near mouse which can have user defined items and launches user defined script sections based on the item selected(clicked).
I've made it so that if u already use the middle mouse button for some purpose then it won't hinder that... it needs the middle mouse button to be pressed for a li'l while more than a normal click (about half a second) to launch the menu... so a simple click won't launch it! ...the delay is configurable too.
Code:
;___________________________________________
;____User Configurable Menu - Rajat_______
;___________________________________________
;You can set any title here for the menu
MenuTitle = -=-=-=-=-=-=-=-
;Delay after which the menu is shown
UMDelay = 20
SetFormat, float, 0.0
SetBatchLines, 10ms
SetTitleMatchMode, 2
;___________________________________________
;_____Menu Definitions______________________
; Create / Edit Menu Items here.
; You can use spaces in values (MenuItems) but not in
; section names.
; Don't worry about the order, the menu will be sorted.
MenuItems = Notepad/Calculator/Section 3/Section 4/Section 5
;___________________________________________
;______Dynamic menuitems here_______________
; Syntax:
; Dyn# = MenuItem|Window title
Dyn1 = MS Word|- Microsoft Word
Dyn2 = Notepad II|- Notepad
;___________________________________________
Exit
;___________________________________________
;_____Menu Sections_________________________
;Create / Edit Menu Sections here.
Notepad:
Run, Notepad.exe
Return
Calculator:
Run, Calc
Return
Section3:
msgbox, You selected 3
Return
Section4:
msgbox, You selected 4
Return
Section5:
msgbox, You selected 5
Return
MSWord:
msgbox, wow! seems like you're working!
Return
NotepadII:
msgbox, this is a dynamic entry
Return
;___________________________________________
;_____Hotkey Section________________________
~MButton::
HowLong = 0
Loop
{
HowLong ++
Sleep, 10
GetKeyState, MButton, MButton, P
IfEqual, MButton, U, Break
}
IfLess, HowLong, %UMDelay%, Return
;prepares dynamic menu
DynMenu =
Loop
{
IfEqual, Dyn%a_index%,, Break
StringGetPos, ppos, dyn%a_index%, |
StringLeft, item, dyn%a_index%, %ppos%
ppos += 2
StringMid, win, dyn%a_index%, %ppos%, 1000
IfWinActive, %win%,
DynMenu = %DynMenu%/%item%
}
;Joins sorted main menu and dynamic menu
Sort, MenuItems, D/
TempMenu = %MenuItems%%DynMenu%
;clears earlier entries
Loop
{
IfEqual, MenuItem%a_index%,, Break
MenuItem%a_index% =
}
;creates new entries
Loop, Parse, TempMenu, /
{
MenuItem%a_index% = %a_loopfield%
}
;creates the menu
Menu = %MenuTitle%
Loop
{
IfEqual, MenuItem%a_index%,, Break
numItems ++
StringTrimLeft, MenuText, MenuItem%a_index%, 0
Menu = %Menu%`n%MenuText%
}
MouseGetPos, mX, mY
HotKey, ~LButton, MenuClick
HotKey, ~LButton, On
ToolTip, %Menu%, %mX%, %mY%
WinActivate, %MenuTitle%
Return
MenuClick:
HotKey, ~LButton, Off
IfWinNotActive, %MenuTitle%
{
ToolTip
Return
}
CoordMode, Mouse, Relative
MouseGetPos, mX, mY
ToolTip
mY -= 3 ;space after which first line starts
mY /= 13 ;space taken by each line
IfLess, mY, 1, Return
IfGreater, mY, %numItems%, Return
StringTrimLeft, TargetSection, MenuItem%mY%, 0
StringReplace, TargetSection, TargetSection, %a_space%,, A
Gosub, %TargetSection%
Return
who says there are limits?!!