Moderators Melba23 Posted June 21, 2010 Moderators Share Posted June 21, 2010 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) EndFuncAs 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:expandcollapse popup#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 EndFuncIt 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. Does anyone have any better ideas? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted June 21, 2010 Share Posted June 21, 2010 Only use one or the other. 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 ( YET)Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 21, 2010 Author Moderators Share Posted June 21, 2010 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? 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. Anyway, I take it you have no better suggestions for coding the tray click differentiation than what I posted above? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted June 21, 2010 Share Posted June 21, 2010 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? 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. Anyway, I take it you have no better suggestions for coding the tray click differentiation than what I posted above? 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now