AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pop-up execution menu...

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
alaricljs



Joined: 06 May 2005
Posts: 15

PostPosted: Fri May 06, 2005 5:42 pm    Post subject: Pop-up execution menu... Reply with quote

Hopefully someone will find this useful. (hey look, I registered! Wink)

This is my derivation of ToolTip Mouse Menu by Rajat. I used it for a while, then decided I wanted something different.

This script uses an INI file to define your menus and hotkeys for them. It uses a ListBox in a window to present the choices. The gui pops at the mouse cursor, and stays within the bounds of your screen. Not tested with multiple monitors. Pressing the hotkey a second time closes the gui. (Why doesn't Escape work? How do I make it work?)

The [Main] section has 1 item:
Menus = Number of menus you are defining, maximum of 8.

Chris: Any chance the Hotkey command could be changed so that an argument can be passed to the code section being executed by the hotkey? It could be part of Options, I picked R for my example Smile
Code:
Hotkey %TheKey%, Menu%a_index%, R%a_index%



The [Menu#] section. # is 1-?? ie: Menu1 It has 5 specific items, plus a variable number of items for commands.
MenuKey = The hotkey definition. ie: #x
MenuSize = Width of menu in pixels (workaround for now, maybe something better will be in a later AHK release)
MenuTitle = Menu title, title bar section of window
MenuLoc = Location of scripts/shortcuts/whatever for this menu. ie: C:\Documents and Settings\All Users\Shortcuts\
MenuItems = The menu definition. | is the seperator, put a space in between to get a blank line. ie: test 1|test2| |test3
This will get you a 4 line menu, a blank line being between test2 and test3

For each item in MenuItems you make an item in the [Menu#] section. You must collapse any spaces ie:
test1 = test.lnk

When you click on the test1 item in the popup the test.lnk link in the C:\Documents and Settings\All Users\Shortcuts\ folder will be executed (using Run).

Code:
CustomColor = EEAA99
CoordMode Mouse, Screen


SetFormat, float, 0.0
SetBatchLines, 10ms
SetTitleMatchMode, 2
#SingleInstance

IniFile = menu.ini

;_________Read the INI file ________________
IfNotExist %IniFile%
{
  MsgBox INI file missing.
  ExitApp
}

IniRead NumMenus, %IniFile%, Main, Menus, 0
If NumMenus = 0
{
  MsgBox No Menus defined in INI file.
  ExitApp
}

If NumMenus > 8
{
  MsgBox Too many Menus defined in INI file.
  ExitApp
}

Loop %NumMenus%
{
  IniRead MenuTitle%a_index%, %IniFile%, Menu%a_index%, MenuTitle
  IniRead MenuItems%a_index%, %IniFile%, Menu%a_index%, MenuItems
  IniRead MenuLoc%a_index%, %IniFile%, Menu%a_index%, MenuLoc
  IniRead MenuSize%a_index%, %IniFile%, Menu%a_index%, MenuSize
  IniRead TheKey, %IniFile%, Menu%a_index%, MenuKey, 0

  Hotkey %TheKey%, Menu%a_index%
}


Exit


Menu1:
MenuNum = 1
Goto Menu

Menu2:
MenuNum = 2
Goto Menu

Menu3:
MenuNum = 3
Goto Menu

Menu4:
MenuNum = 4
Goto Menu

Menu5:
MenuNum = 5
Goto Menu

Menu6:
MenuNum = 6
Goto Menu

Menu7:
MenuNum = 7
Goto Menu

Menu8:
MenuNum = 8
Goto Menu


Menu:
TempMenu := MenuItems%MenuNum%
MenuTitle := MenuTitle%MenuNum%
MenuSize := MenuSize%MenuNum%
GuiNum := MenuNum + 1
If Show%MenuNum% =
{
  If Is%MenuNum% =
  {
    GoSub Here
    Is%MenuNum% = 1
  }
  GoSub DoShow
  Show%MenuNum% = 1
}
Else
{
  Show%MenuNum% =
  Gui %GuiNum%:Cancel
}
Return


Here:
Gui %GuiNum%:+AlwaysOntop +LastFound
Gui %GuiNum%:Color, %CustomColor%, Gray

numItems = 0

Loop, Parse, TempMenu, |
{
  numItems ++
}


Gui %GuiNum%:Add, ListBox, Multi Center x-0 y-0 W%MenuSize% R%numItems% vMyChoice gMyChoice, %TempMenu%
WinSet TransColor, %CustomColor% 225
Gui %GuiNum%:-MinimizeBox ToolWindow

Return


DoShow:
GuiControlGet MyChoice, %GuiNum%:Pos
MouseGetPos mX, mY
Gui %GuiNum%:Show, x%Mx% y%My% W%MyChoiceW% H%MyChoiceH%, %MenuTitle%
PostMessage 0x185, 0, -1, ListBox1, %MenuTitle%

WinGetPos,,, MyW, MyH, %MenuTitle%

Move = 0

If (mX + MyW > A_ScreenWidth)
{
  Move = 1
  mX := A_ScreenWidth - MyW
}
If (mY + MyH > A_ScreenHeight)
{
  Move = 1
  mY := A_ScreenHeight - MyH
}

If (Move = 1)
{
  WinMove %MenuTitle%,, %mX%, %mY%
}

Return

MyChoice:
Gui %A_Gui%:Cancel
GuiControlGet MyChoice, %A_Gui%:
StringTrimLeft TargetSection, MyChoice, 0
StringReplace TargetSection, TargetSection, %a_space%,, A
If TargetSection
{
  Num := A_Gui - 1
  Loc := MenuLoc%Num%

  IniRead Command, %IniFile%, Menu%Num%, %TargetSection%
  Run %Command%, %Loc%
}
Return


GuiEscape:
GuiClose:
Gui %A_Gui%:Cancel
Return


Here is a sample Menu.ini:

Code:
[Main]
Menus = 2

[Menu1]
MenuKey = #x
MenuSize = 85
MenuTitle = -=[ X ]=-
MenuLoc = C:\Documents and Settings\All Users\X-Sessions\
MenuItems = host1|host2||hostA|hostB

host1 = host1.lnk
host2 = host2.lnk
hostA = jabba.lnk
hostB = foobar.lnk

[Menu2]
MenuKey = #p
MenuSize = 100
MenuTitle = -=[ Programs ]=-
MenuLoc = C:\Documents and Settings\All Users\My Documents\Program Links\
MenuItems = Elements|Photoshop|Irfan View| |Excel|Word|Visio| |Nero|Alcohol| |WinAmp| |WinSCP

Alcohol = Alcohol.lnk
Elements = Elements 3.0.lnk
Excel = Excel.lnk
Nero = Nero.lnk
Photoshop = Photoshop.lnk
Visio = Visio 2003.lnk
WinAmp = WinAmp.lnk
WinSCP = WinSCP.lnk
Word = Word.lnk
IrfanView = IrfanView.lnk


Let me know if this explains it well enough. Hell, let me know if you think it's worth my time Smile
_________________
Spoon!
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat May 07, 2005 12:13 am    Post subject: Re: Pop-up execution menu... Reply with quote

alaricljs wrote:
Any chance the Hotkey command could be changed so that an argument can be passed to the code section being executed by the hotkey? It could be part of Options, I picked R for my example Smile
Code:
Hotkey %TheKey%, Menu%a_index%, R%a_index%
That's an interesting idea. I've made a note to research whether the hotkey command (and perhaps the menu command) can be easily extended to optionally call functions instead of subroutines.
Back to top
View user's profile Send private message Send e-mail
Atomhrt



Joined: 02 Sep 2004
Posts: 124
Location: Sunnyvale

PostPosted: Sat May 07, 2005 6:22 pm    Post subject: Reply with quote

I think it's a cool idea, but would it be possible to have sub-menus instead of separate menus?

Here is an example: Screen shot

Note that each sub-menu is an actual directory (two are symbolic links to other directories) and each directory has .lnk and .exe files in them.
_________________
I am he of whom he speaks!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group