Sign in to follow this  
Followers 0
BartW

Catch Mouse Double click help

4 posts in this topic

HI all,

I have writen a script that wen i double click a list view item , it opens list view item in a MsgBox.

what i do is catch the first mouse click and then the second en then compair the time and moice point with each other and if it is in a set value then it is a double mouse click.

but i was wondering if ther was a better way of doing it.

Thanks in advance for the answers

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Local $listview, $button, $item1, $item2, $item3, $input1, $msg , $Mousedowncounter ,$Mousedowninfo1 ,$Mousedowninfo2 ,$Info1 ,$Info2 , $Infocontrole ,$Mousepos ,$timeclear ,$Double
Example()

Func Example()


GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
$input1 = GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
GUISetState()
GUICtrlSetData($item2, "ITEM1")
GUICtrlSetData($item3, "||COL33")
GUICtrlDelete($item1)
$Mousedowncounter = 1
Do
$msg = GUIGetMsg()
$timeclear = StringSplit($Mousedowninfo1,"|");clear the mouse timers
If IsArray($timeclear)then
     If $timeclear[0] > 1 Then
         if $timeclear[1] + 700 < @MON&@MDAY&@HOUR&@MIN&@SEC&@MSEC Then ;checks if the date time is biger then 700 msec than reset the doubel click
             $Mousedowncounter = 1
             $Mousedowninfo1 = ""
             $Mousedowninfo2 = ""
         EndIf
     EndIf
EndIf

Select
     Case $msg = $button
             MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
     Case $msg = $listview
             MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
     Case $msg = $GUI_EVENT_PRIMARYDOWN
             $Mousepos = MouseGetPos ()
             if $Mousedowncounter = 1 then
                         $Mousedowninfo1 = @MON&@MDAY&@HOUR&@MIN&@SEC&@MSEC&"|"&$Mousepos[0]&"|"&$Mousepos[1] ; Mm ,dd ,hh, min ,msec |Mouse x pos |Mouse y pos
                         $Mousedowncounter = 2
             ElseIf $Mousedowncounter = 2 Then
                         $Mousedowninfo2 = @MON&@MDAY&@HOUR&@MIN&@SEC&@MSEC&"|"&$Mousepos[0]&"|"&$Mousepos[1] ; Mm ,dd ,hh, min ,msec |Mouse x pos |Mouse y pos
                         $Double = MouseDoubleClick ()
             EndIf
     Case $Double = True
             MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2);open msgbox white the selected info.
             $Double = False
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example

Func MouseDoubleClick ()
$Info1 = StringSplit($Mousedowninfo1,"|");split the info in Datetime|Mouse x pos |Mouse y pos
$Info2 = StringSplit($Mousedowninfo2,"|");split the info in Datetime|Mouse x pos |Mouse y pos
If $Info1[1] + 500 > $Info2[1] Then;checks if the date time 2 is within the 500 msec of date time 1
if $Info1[2] + 10 > $Info2[2] then ;checks if the Xpos 2 is within the +10 of Xpos 1
$Infocontrole &= 1
Elseif $Info1[2] - 10 < $Info2[2] then;checks if the Xpos 2 is within the -10 of Xpos 1
$Infocontrole &= 1
Else
$Infocontrole &= 0
EndIf
if $Info1[3] + 10 > $Info2[3] then ;checks if the Ypos 2 is within the +10 of Ypos 1
$Infocontrole &= 1
Elseif $Info1[3] - 10 < $Info2[3] then ;checks if the Ypos 2 is within the -10 of Ypos 1
$Infocontrole &= 1
Else
$Infocontrole &= 0
EndIf
EndIf
IF $Infocontrole = 11 THEN
$Mousedowninfo1 = ""
$Mousedowninfo2 = ""
$Infocontrole = ""
$Mousedowncounter = 1
Return true
Else
$Mousedowninfo1 = ""
$Mousedowninfo2 = ""
$Infocontrole = ""
$Mousedowncounter = 1
Return False
EndIf
EndFunc

Share this post


Link to post
Share on other sites



The best way to do this, detecting double clicking a listview item, is to use the Windows message using GUIRegisterMsg and the $WM_Notify message. Look in the help file for _GUICtrlListView_Create, in the example script for that function is a large list of Windows messages and ways to detect and interact with them. Look for Func WM_NOTIFY in the example script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanx BrewManNH.

That was what i was looking for

Share this post


Link to post
Share on other sites

Glad I could help. ;)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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