Normally the tray menu is displayed whenever the user right-click the tray icon.
And you can set a default item for when you double-click the tray.
A lot of people I guess (including myself) would like to launch a specific subroutine or simply display the same tray menu if the user left-clic this icon, or double left-click it.
This is something I wanted to do from a long time, but as I couldn't find anything doing searches I thought it was not feasable until I found very old threads about that.
EDIT : After looking for "AHK_NOTIFYICON" which is the magic solution I found numerous threads but none seem to me very very clear in the title or with partial answer to the large point so I hope maybe this one will be more visible.
topics examples :
[Solved] Single-click tray icon without a tray item - AHKScript (an AutoHotkey Forum) - Mozilla Firefox
http://ahkscript.org/boards/viewtopic.php?t=6110
How do i change the actions of clicking the tray icon - Ask for Help - AutoHotkey Community - Mozilla Firefox
http://www.autohotkey.com/board/topic/6 ... /?p=391707
Show tray menu if Left Click (thanks goes to Lexikos) - Ask for Help - AutoHotkey Community - Mozilla Firefox
http://www.autohotkey.com/board/topic/3 ... o-lexikos/
So thanks Lexikos for the OnMessage(0x404, "AHK_NOTIFYICON") solution.
Here is a sum-up that I think can be helpful to others and should even be included in the documentation.
To recognize what the user makes on tray icon, one should simply add to the top auto-execute part of his script :
Code: Select all
OnMessage(0x404, "AHK_NOTIFYICON")
Code: Select all
AHK_NOTIFYICON(wParam, lParam)
{
if (lParam = 0x202) { ; user left-clicked tray icon
;ADD ANY SUBROUTINE OR FUNCTION HERE
return
}
else if (lParam = 0x203) {; user double left-clicked tray icon
;ADD ANY SUBROUTINE OR FUNCTION HERE
return
}
if (lParam = 0x204) { ; user right-clicked tray icon
;ADD ANY SUBROUTINE OR FUNCTION HERE
return
}
if (lParam = 0x208) { ; user middle-clicked tray icon
;ADD ANY SUBROUTINE OR FUNCTION HERE
return
}
}
Code: Select all
Menu, Tray, Show
I tried to distinguish and tried some timer/static/global variable tricks but couldn't really understand what was happening.
Anyway in the meantime this solution with timers seems to be working well:
Code: Select all
AHK_NOTIFYICON(wParam, lParam)
{
if (lParam = 0x202) {
Settimer, Tray_SingleLclick, -400
return 1
}
else if (lParam = 0x203) {
Settimer, Tray_DoubleLclick, -150
return 1
}
}
Tray_DoubleLclick:
loop 2
Settimer, Tray_SingleLclick, Off
msgbox You Double left-clicked tray icon
return
Tray_SingleLclick:
msgbox You left-clicked tray icon
return
Thanks and see ya!