AutoHotkey Community

It is currently May 26th, 2012, 11:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Pop-up execution menu...
PostPosted: May 6th, 2005, 6:42 pm 
Offline

Joined: May 6th, 2005, 6:26 pm
Posts: 15
Hopefully someone will find this useful. (hey look, I registered! ;))

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 :)
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 :)

_________________
Spoon!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 7th, 2005, 1:13 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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 :)
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2005, 7:22 pm 
Offline

Joined: September 2nd, 2004, 1:08 am
Posts: 124
Location: Sunnyvale
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!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], oldbrother, Rajat and 62 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group