Jump to content

ListViewItem and double click


LOULOU
 Share

Recommended Posts

You have to set up a timer to do what you want. Keep some type of time log for when a mouse click is made, and if another is made within about 500ms then call the doubleclick function.

EDIT: spelling

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

Here is my small example that I used days ago for testing and rewrote it a little bit :lmao:

#include <GUIConstants.au3>

GUICreate("test")

$msginfo    = GUICtrlCreateLabel("",0,0,100,20)
$clicktime  = GUICtrlCreateLabel("",100,0,100,20)
$mouseclick = GUICtrlCreateLabel("normal",100,20,40,20)

$listv      = GUICtrlCreateListView("Name|Firstname",50,100,250,100)
$item1      = GUICtrlCreateListViewItem("Black|Mr.",$listv)
$item2      = GUICtrlCreateListViewItem("White|Dr.",$listv)

GUISetState()

$start  = 0
$diff   = 0
$doubleclicked = 0

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
            
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $diff = TimerDiff($start)
            GUICtrlSetData($clicktime,$diff)
            
        ; Read the current mouse-doubleclick-settings from registry
            $mousespeed = RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed")
            If $mousespeed = "" Then $mousespeed = 500
            
            If $diff < $mousespeed And $doubleclicked = 0 Then
                GUICtrlSetData($mouseclick,"double")
                $itemclicked = GUICtrlRead($listv)
                If $itemclicked > 0 Then
                    Msgbox(64,"Item clicked",GUICtrlRead($itemclicked))
                EndIf
                $doubleclicked = 1
            Else
                GUICtrlSetData($mouseclick,"normal")
                $doubleclicked = 0
            EndIf
            $start = TimerInit()
    EndSelect
    
    GUICtrlSetData($msginfo,$msg)
WEnd

GUIDelete()

Exit

So long...

Holger

Link to comment
Share on other sites

  • 2 weeks later...

This works great till you add a menu, the menu works fine as long

as the listview is not clicked even one time

the below is modified for the above problem, need help in how to resolve this.

Here is my small example that I used days ago for testing and rewrote it a little bit :lmao:

#include <GUIConstants.au3>

GUICreate("test")
$menuFile = GUICtrlCreateMenu ("&File")
$menuFileExit = GUICtrlCreateMenuitem ("Exit",$menuFile)

$msginfo    = GUICtrlCreateLabel("",0,0,100,20)
$clicktime    = GUICtrlCreateLabel("",100,0,100,20)
$mouseclick    = GUICtrlCreateLabel("normal",100,20,40,20)

$listv        = GUICtrlCreateListView("Name|Firstname",50,100,250,100)
$item1        = GUICtrlCreateListViewItem("Black|Mr.",$listv)
$item2        = GUICtrlCreateListViewItem("White|Dr.",$listv)

GUISetState()

$start    = 0
$diff    = 0
$doubleclicked = 0

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
            
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $menuFileExit
            ExitLoop
            
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $diff = TimerDiff($start)
            GUICtrlSetData($clicktime,$diff)
            
        ; Read the current mouse-doubleclick-settings from registry
            $mousespeed = RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed")
            If $mousespeed = "" Then $mousespeed = 500
            
            If $diff < $mousespeed And $doubleclicked = 0 Then
                GUICtrlSetData($mouseclick,"double")
                $itemclicked = GUICtrlRead($listv)
                If $itemclicked > 0 Then
                    Msgbox(64,"Item clicked",GUICtrlRead($itemclicked))
                EndIf
                $doubleclicked = 1
            Else
                GUICtrlSetData($mouseclick,"normal")
                $doubleclicked = 0
            EndIf
            $start = TimerInit()
    EndSelect
    
    GUICtrlSetData($msginfo,$msg)
WEnd

GUIDelete()

Exit

So long...

Holger

<{POST_SNAPBACK}>

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Didn't get any help on this one, so kept playing with ideas, this works

It's not perfect but at least it works

This allows to have menus and a primarydown (used for double clicking a item in

the listview)

#include <GUIConstants.au3>

$main_window = GUICreate("test",500,500,-1,-1)
$menuFile = GUICtrlCreateMenu ("&File")
$menuFileExit = GUICtrlCreateMenuitem ("Exit",$menuFile)

$msginfo    = GUICtrlCreateLabel("",0,0,100,20)
$clicktime  = GUICtrlCreateLabel("",100,0,100,20)
$mouseclick = GUICtrlCreateLabel("normal",100,20,40,20)

$exit = GUICtrlCreateButton ("Exit",355,450,120,20)
GUICtrlSetState($exit,$GUI_FOCUS)            ; the focus is on this button

$listv      = GUICtrlCreateListView("Name|Firstname",50,100,250,100)
$item1      = GUICtrlCreateListViewItem("Black|Mr.",$listv)
$item2      = GUICtrlCreateListViewItem("White|Dr.",$listv)

GUISetState()

$start  = 0
$diff   = 0
$doubleclicked = 0

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
            
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $exit Or $msg = $menuFileExit
            ExitLoop
            
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            Local $focus = ControlGetFocus(WinGetTitle(""))
            If($focus == "SysListView321") Then
                $diff = TimerDiff($start)
                GUICtrlSetData($clicktime,$diff)
                
        ; Read the current mouse-doubleclick-settings from registry
                $mousespeed = RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed")
                If $mousespeed = "" Then $mousespeed = 500
                
                If $diff < $mousespeed And $doubleclicked = 0 Then
                    GUICtrlSetData($mouseclick,"double")
                    $itemclicked = GUICtrlRead($listv)
                    If $itemclicked > 0 Then
                        Msgbox(64,"Item clicked",GUICtrlRead($itemclicked))
                    EndIf
                    $doubleclicked = 1
                Else
                    GUICtrlSetData($mouseclick,"normal")
                    $doubleclicked = 0
                EndIf
                $start = TimerInit()
            EndIf
        Case $msg = $GUI_EVENT_PRIMARYUP
            GUICtrlSetState($exit,$GUI_FOCUS)            ; the focus is on this button, take the focus away from the listview
    EndSelect
    
    GUICtrlSetData($msginfo,$msg)
WEnd

GUIDelete()

Exit

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 8 months later...

Try this. It verifies mouse position. I tried to use this on a list box but the list box grabs the double click. This forces you to triple click when used on a list box.

#include <GUIConstants.au3>

$main_window = GUICreate("test",500,500,-1,-1)
$menuFile = GUICtrlCreateMenu ("&File")
$menuFileExit = GUICtrlCreateMenuitem ("Exit",$menuFile)

$msginfo    = GUICtrlCreateLabel("",0,0,100,20)
$clicktime  = GUICtrlCreateLabel("",100,0,100,20)
$mouseclick = GUICtrlCreateLabel("normal",100,20,40,20)

$exit = GUICtrlCreateButton ("Exit",355,450,120,20)
GUICtrlSetState($exit,$GUI_FOCUS)           ; the focus is on this button

dim $listLoc[4]

$listv      = GUICtrlCreateListView("Name|Firstname",50,100,400,100)
$item1      = GUICtrlCreateListViewItem("Black|Mr.",$listv)
$item2      = GUICtrlCreateListViewItem("White|Dr.",$listv)

GUISetState()

$start  = 0
$diff   = 0
$doubleclicked = 0
dim $lastPos[2]

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
            
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $exit Or $msg = $menuFileExit
            ExitLoop
            
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $diff = TimerDiff($start)
            GUICtrlSetData($clicktime,$diff)
                
        ; Read the current mouse-doubleclick-settings from registry
            $mousespeed = RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed")
            If $mousespeed = "" Then $mousespeed = 500
            
            If $diff < $mousespeed And $doubleclicked = 0 and not ValidDoubleClick($lastPos, MouseGetPos(), "SysListView321") Then
                GUICtrlSetData($mouseclick,"double")
                $itemclicked = GUICtrlRead($listv)
                If $itemclicked > 0 Then
                    Msgbox(64,"Item clicked",GUICtrlRead($itemclicked))
                EndIf
                $doubleclicked = 1
            Else
                GUICtrlSetData($mouseclick,"normal")
                $doubleclicked = 0
                $lastPos = MouseGetPos()
            EndIf
            $start = TimerInit()

    EndSelect
    
    GUICtrlSetData($msginfo,$msg)
WEnd

GUIDelete()

Exit

Func ValidDoubleClick($old, $new, $control)

    $handle = ControlGetHandle(WinGetTitle(""), "", $control)

    AutoItSetOption("WinTitleMatchMode", 4)
    $pos = WinGetPos ($handle, "")
    AutoItSetOption("WinTitleMatchMode", 1)

    if $new[0] < $pos[0] or $new[0] > ($pos[0] + $pos[2]) then return 1
    if $new[1] < $pos[1] or $new[1] > ($pos[1] + $pos[3]) then return 1

    $dx = $old[0] - $new[0]
    $dy = $old[1] - $new[1]
    
    if $dx < -4 or $dx > 4 or $dy < -4 or $dy > 4  then return 1
    
    return 0
    
EndFunc
Link to comment
Share on other sites

Be warned: Still shows double click if you double click on the column headings. I can live with that.

Can be used as a feature. B)

Simple click = Sort ascending, Double click = Sort descending.

Maybe less work as to store the last used sort direction.

Thanks to all, for the examples, Reinhard

Link to comment
Share on other sites

  • 2 weeks later...

another modification/solution, works very well for me

...
Opt("GUIOnEventMode",1)
...
$dbl_oldx=0
$dbl_oldy=0
$dbl_StartTime=0
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"mouseClicks")
...

Func _DoubleClicked($winhandle,$ControlHandle=0)
        Local $info= GUIGetCursorInfo ($winhandle)
        Local $diff = TimerDiff($dbl_startTime) 
        Local $mousespeed = RegRead("HKCU\Control Panel\Mouse","DoubleClickSpeed")
        If $mousespeed = "" Then $mousespeed = 500
        
        IF $diff < $mousespeed and $dbl_oldx=$info[0] and $dbl_oldy=$info[1] Then
           $dbl_oldx=0
           $dbl_oldy=0
           $dbl_StartTime=0
           If $ControlHandle=0 Then
               return $info[4]
           Else
             if $ControlHandle=$info[4] Then
                 return True
             Else
                 return False
             Endif
           Endif
       Else
            $dbl_oldx=$info[0]
            $dbl_oldy=$info[1]
            $dbl_StartTime=TimerInit()
        Endif
EndFunc 

Func mouseClicks()  
    Select
    Case _DoubleClicked($GUIHandle,$ListViewHandle)
        ConsoleWrite(_GUICtrlListViewGetCurSel($ListViewHandle))
    EndSelect
Endfunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...