Single or Double Left Click Tray Icon : Subroutine or display menu

Helpful script writing tricks and HowTo's
Posts: 118
Joined: 19 May 2014, 04:55

Single or Double Left Click Tray Icon : Subroutine or display menu

15 Sep 2015, 16:18

Hi !

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
How do i change the actions of clicking the tray icon - Ask for Help - AutoHotkey Community - Mozilla Firefox ... /?p=391707
Show tray menu if Left Click (thanks goes to Lexikos) - Ask for Help - AutoHotkey Community - Mozilla Firefox ... 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] [Download] GeSHi © Codebox Plus

OnMessage(0x404, "AHK_NOTIFYICON")

and then add this as a function:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

If you want to display tray icon as it was right clicked, just put this line as action:

The problem is when the user double left-click, both lParam 0x202 and 0x203 are sent.

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] [Expand] [Download] GeSHi © Codebox Plus

So, can it be maybe completed/adjusted and put into documentation? :roll:

Thanks and see ya! :)
Knowledge is knowing a tomato is a fruit; wisdom is not putting it in a fruit salad. (Miles Kington)

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 4 guests