I'm sure this question has been asked many, many a times already, but I tried a search, and what I saw didn't answer my question, and there were too many results to read them all - sorry.
Right now if I right click on the tray icon, it shows the menu I made. What I want to be able to do is left click and have a menu show. I'd rather learn how to have it show an arbitrary menu (that I choose) - or I can recreate the tray menu if necessary.
Show tray menu if Left Click (thanks goes to Lexikos)
Started by
animeaime
, Nov 14 2008 11:08 AM
9 replies to this topic
#1
-
Posted 14 November 2008 - 11:08 AM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
#Persistent Menu, Tray, NoStandard Menu, Tray, Add, Show Menu, ShowMenu Menu, Tray, Default, Show Menu Menu, Tray, Click, 1 Menu, Tray, Standard Return ShowMenu: Menu, Tray, Show Return
#2
-
Posted 14 November 2008 - 11:24 AM
Do I have to have a menu item?... It creates negative side effects if the user clicks it from the menu. Also, it doesn't look nice...
But thanks for the idea, never thought of doing that. Going to see if there isn't a way to show the menu using your idea, but without having an item.
But thanks for the idea, never thought of doing that. Going to see if there isn't a way to show the menu using your idea, but without having an item.
#3
-
Posted 14 November 2008 - 11:33 AM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
Just an update. Rather than using the menu, is there a way to design a hotkey (for LButton) to do what I want? I mean if there is a way to use the menu, awesome, but if not, that's another possibility I'm checking on.
#4
-
Posted 14 November 2008 - 11:54 AM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
Okay.. Here is Lexikos method
Menu, M, Add, Note that this is, DoNothing Menu, M, Add, NOT the tray menu., DoNothing OnMessage(0x404, "AHK_NOTIFYICON") [color=red]Return[/color] ; code Edited.. thanks animeaime AHK_NOTIFYICON(wParam, lParam) { if (lParam = [color=red]0x202[/color]) ; [color=red]WM_LBUTTONUP[/color] { SetTimer, ShowRbuttonMenu, -1 return 0 } } ShowRbuttonMenu: Menu, M, Show DoNothing: return
#5
-
Posted 14 November 2008 - 12:01 PM
Awesome...exactly what I need. Only adjustment I made was adding a return statement after the OnMessage. This way, the menu won't pop open when the script loads. But, beside that small part, awesome. Thank you for this and of course thank you Lexikos.
#6
-
Posted 14 November 2008 - 12:34 PM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
I modified the Lexikos method and added some "spunk".
What the code does is allows the toggling of the left/right click menus.
If the user left clicks, the left click menu will open. Left click again, and the menu will close.
Same with right click. If the user right clicks, the right click menu will open. Right click again, and the menu will close.
If you left click, then right click, then the right click menu will open (and the left click menu will close). Similarly, if you right click, then left click, then the left click menu will open (and the right click menu will close).
Thank you Lexikos for this great method.
Edit:
Here is alternate way to do it (if you don't want to use the Tray menu for some reason).
The only changes is that mentions of "Tray" are replaced by "RightClickMenu".
Then the line: "Menu, tray, NoStandard" is moved before the menu creation. This prevents double-clicking the icon from opening the script (for non-compiled scripts).
Enjoy.
What the code does is allows the toggling of the left/right click menus.
If the user left clicks, the left click menu will open. Left click again, and the menu will close.
Same with right click. If the user right clicks, the right click menu will open. Right click again, and the menu will close.
If you left click, then right click, then the right click menu will open (and the left click menu will close). Similarly, if you right click, then left click, then the left click menu will open (and the right click menu will close).
Thank you Lexikos for this great method.
#SingleInstance Force #NoEnv ;Global variables ;Left-click and right-click menus are not open when script begins LeftClickMenuOpen := 0 RightClickMenuOpen := 0 ;Program Start gosub CreateLeftClickMenu gosub CreateRightClickMenu OnMessage(0x404, "AHK_NOTIFYICON") return CreateLeftClickMenu: Menu, LeftClickMenu, add, LeftClick, Test Menu, LeftClickMenu, add Menu, LeftClickMenu, add, % "Exit", ExitProgram return CreateRightClickMenu: Menu, tray, NoStandard Menu, tray, add, RightClick, Test Menu, tray, add Menu, tray, add, % "Exit", ExitProgram return Test: MsgBox, % A_ThisMenu . "@" . A_ThisMenuItem . "@" . A_ThisMenuItemPos return /* Lexikos method of detecting Left mouse click on ToolTray (modified) If left click and left-click menu open, close left-click menu If left click and left-click menu not open, open left-click menu (and close right-click menu, if open) If right click and right-click menu open, close right-click menu If right click and right-click menu not open, open right-click menu (and close left-click menu, if open) */ AHK_NOTIFYICON(wParam, lParam) { global LeftClickMenuOpen, RightClickMenuOpen if (lParam = 0x202) ; WM_LBUTTONUP { ;Close right-click menu RightClickMenuOpen := 0 if (LeftClickMenuOpen) { ;If left-click menu is open, close it Send {Esc} } else { ;If left-click menu is not open, open it Menu, LeftClickMenu, Show } ;Toggle state of left-click menu ;Open to close ;Close to open LeftClickMenuOpen := !LeftClickMenuOpen } else if (lParam = 0x205) ; WM_RBUTTONUP { ;Close left-click menu LeftClickMenuOpen := 0 if (RightClickMenuOpen) { ;If right-click menu is open, close it Send {Esc} } else { ;If right-click menu is not open, open it Menu, Tray, Show } ;Toggle state of right-click menu ;Open to close ;Close to open RightClickMenuOpen := !RightClickMenuOpen } return 0 } ExitProgram: ExitApp
Edit:
Here is alternate way to do it (if you don't want to use the Tray menu for some reason).
The only changes is that mentions of "Tray" are replaced by "RightClickMenu".
Then the line: "Menu, tray, NoStandard" is moved before the menu creation. This prevents double-clicking the icon from opening the script (for non-compiled scripts).
Enjoy.
#SingleInstance Force #NoEnv ;Global variables ;Left-click and right-click menus are not open when script begins LeftClickMenuOpen := 0 RightClickMenuOpen := 0 ;Program Start Menu, Tray, NoStandard gosub CreateLeftClickMenu gosub CreateRightClickMenu OnMessage(0x404, "AHK_NOTIFYICON") return CreateLeftClickMenu: Menu, LeftClickMenu, add, LeftClick, Test Menu, LeftClickMenu, add Menu, LeftClickMenu, add, % "Exit", ExitProgram return CreateRightClickMenu: Menu, RightClickMenu, add, RightClick, Test Menu, RightClickMenu, add Menu, RightClickMenu, add, % "Exit", ExitProgram return Test: MsgBox, % A_ThisMenu . "@" . A_ThisMenuItem . "@" . A_ThisMenuItemPos return /* Lexikos method of detecting Left mouse click on ToolTray (modified) If left click and left-click menu open, close left-click menu If left click and left-click menu not open, open left-click menu (and close right-click menu, if open) If right click and right-click menu open, close right-click menu If right click and right-click menu not open, open right-click menu (and close left-click menu, if open) */ AHK_NOTIFYICON(wParam, lParam) { global LeftClickMenuOpen, RightClickMenuOpen if (lParam = 0x202) ; WM_LBUTTONUP { ;Close right-click menu RightClickMenuOpen := 0 if (LeftClickMenuOpen) { ;If left-click menu is open, close it Send {Esc} } else { ;If left-click menu is not open, open it Menu, LeftClickMenu, Show } ;Toggle state of left-click menu ;Open to close ;Close to open LeftClickMenuOpen := !LeftClickMenuOpen } else if (lParam = 0x205) ; WM_RBUTTONUP { ;Close left-click menu LeftClickMenuOpen := 0 if (RightClickMenuOpen) { ;If right-click menu is open, close it Send {Esc} } else { ;If right-click menu is not open, open it Menu, RightClickMenu, Show } ;Toggle state of right-click menu ;Open to close ;Close to open RightClickMenuOpen := !RightClickMenuOpen } return 0 } ExitProgram: ExitApp
#7
-
Posted 14 November 2008 - 01:10 PM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
Thank you Lexikos for this great method.
I am not sure if he reads every post. You may thank him in the subject line itself.. or maybe send him a PM
#8
-
Posted 14 November 2008 - 01:30 PM
k, thanks I'll send him a PM.
#9
-
Posted 14 November 2008 - 02:10 PM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.
There's only one problem...if the user presses escape, I'm not sure how to catch this to make sure both menus are set to not open. I'm looking it up, but if anyone has any hints, I'm listening.
Edit:
Sorry about all the fuss. Figured it out. Can't seem to understand why I can't make a function, and put this in an else branch, but oh well, it works.
Here is the code I added to the top of the AHK_NOTIFYICON fuction (right after the global statement). It sees if Escape is pressed. If so, it sets the LeftClickMenu and RightClickMenu to not open.
Edit:
Sorry about all the fuss. Figured it out. Can't seem to understand why I can't make a function, and put this in an else branch, but oh well, it works.
Here is the code I added to the top of the AHK_NOTIFYICON fuction (right after the global statement). It sees if Escape is pressed. If so, it sets the LeftClickMenu and RightClickMenu to not open.
GetKeyState, state, Escape if (state == "D") { ;Escape key was pressed LeftClickMenuOpen := 0 RightClickMenuOpen := 0 return 0 }
#10
-
Posted 14 November 2008 - 03:59 PM
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts.
Add OOP to your scripts via the Class Library. Check out my scripts.