Sign in to follow this  
Followers 0
Melba23

Tray Icon Click vs DoubleClick

4 posts in this topic

Hi all,

I have been playing around with the tray icon - as one does - and found that I had difficulty in distinguishing between Single and Double clicks as shown here:

#include <Constants.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

TraySetState()

TraySetClick(16)

; Set left click
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")

TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "On_DblClick")

While 1
    Sleep(10)
WEnd

Func On_Exit()
    Exit
EndFunc

Func On_Click()
    ConsoleWrite("Single" & @CRLF)
EndFunc

Func On_DblClick()
    ConsoleWrite("Double" & @CRLF)
EndFunc

As the above code shows, there is no problem in identifying Single clicks, but Double clicks also show up as 2 Single clicks - usually one before and one after the Double.

Searching turned up one or two posts on this, all suggestions involving Adlib and flags. Based on what I found - and a bit of original thought - the simplest code I have been able to come up with is this:

#include <Constants.au3>

$aRet = DllCall("user32", "long", "GetDoubleClickTime")
Global $iDbleClickTime = $aRet[0]
ConsoleWrite($iDbleClickTime & @CRLF)

Global $fDbleClick = False

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)

TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

TraySetState()

; Right click only for menu
TraySetClick(16)

; Set left click
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "On_Click")
; Set left dble click
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "On_DblClick")

While 1
    Sleep(10)
WEnd

Func On_Exit()
    Exit
EndFunc

Func On_Click()
    AdlibRegister("TrayClickChecker", $iDbleClickTime)
EndFunc

Func On_DblClick()
    $fDbleClick = True
EndFunc

Func TrayClickChecker()
    AdlibUnRegister("TrayClickChecker")
    If $fDbleClick Then
        ConsoleWrite("Double Click" & @CRLF)
        $fDbleClick = False
    Else
        ConsoleWrite("Click" & @CRLF)
    EndIf
EndFunc

It works, but it does require you to wait until the end of DoubleClickTime to get a reaction (500ms in my case) and it seems a bit of a roundabout way of doing it. :mellow:

Does anyone have any better ideas? :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites



Only use one or the other. Posted Image

How is the program supposed to know in advance whether the user is going to click again in the next 500ms is the question you're asking. Typically I click for slightly longer when single clicking etc. But thats all a lot of work and rather pointless. If you look at it from the computers point of view, you'll see that you're asking to read your mind, and as well all know that is sadly not the case (Posted Image YET)

Mat

Share this post


Link to post
Share on other sites

Mat,

I take your point, but I was surprised that Windows does not do better at helping to determine the result for you. I can easily accept a SingleClick beforehand - as you say, how can it read your mind - but I was very surprised by the second SingleClick afterwards. If Windows has decided that a DoubleClick has occured, why not eat the second SingleClick? :mellow:

I have just remembered this thread where we were discussing how to differentiate between Single and Double clicks on controls using WM_COMMAND - it seems as if the second Click message is indeed eaten there - which makes me even more annoyed that it does not seem to happen in the tray icon case. :P

Anyway, I take it you have no better suggestions for coding the tray click differentiation than what I posted above? :party:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Mat,

I take your point, but I was surprised that Windows does not do better at helping to determine the result for you. I can easily accept a SingleClick beforehand - as you say, how can it read your mind - but I was very surprised by the second SingleClick afterwards. If Windows has decided that a DoubleClick has occured, why not eat the second SingleClick? :mellow:

I have just remembered this thread where we were discussing how to differentiate between Single and Double clicks on controls using WM_COMMAND - it seems as if the second Click message is indeed eaten there - which makes me even more annoyed that it does not seem to happen in the tray icon case. :P

Anyway, I take it you have no better suggestions for coding the tray click differentiation than what I posted above? :party:

M23

It would also appear that the messages are queued so that you will not recieve the double click notification until the single click event has completed. This is particularly clear when you double click this:

#include<Constants.au3> ; $TRAY_*

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)

TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

TraySetState()

TraySetClick(16)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_Click")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "_DblClick")

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc

Func _Click()
    MsgBox(0, "Ummm", "Wat?")
    ConsoleWrite("Single click." & @CRLF)
EndFunc

Func _DblClick()
    ConsoleWrite("Double click." & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0