Jump to content

[SOLVED] Detect Double Click


Recommended Posts

Hi friends,

Is there any way to detect the left double clicks like we get the primary clicks  using _IsPressed("01").

We can detect double clicks by initiating a timer and finding the delay between left clicks on same coordinates but still want to if there is a better direct way.

Thank you friends.

 

#Include <Misc.au3> ; Used for the _IsPressed
 HotKeySet("{ESC}", "_ExitScript") ;Hot key Esc to Exit script
 $nCountClick = 0 ;Click Count
 While 1 ; Loop until user presses ESc to exit the Recorder
        If _IsPressed("01") then ; If left mouse is pushed.
            While (_IsPressed("01")) ;Wait until user releases button
                Sleep(100)
            WEnd
            $pos = MouseGetPos() ; Get the position.
            $nCountClick = $nCountClick + 1 ;Add click count
            ToolTip($nCountClick & ") " & 'Left Clicked X: ' & $pos[0] & ', Y: ' & $pos[1]) ;Show the click count with position
        EndIf
 WEnd

Func _ExitScript() ;HotKet method to Exit script
    Exit
EndFunc ;=> _ExitScript

 

Link to comment
Share on other sites

If _IsPressed('01') Then
     $iPos = MouseGetPos()
     While 1
     If _IsPressed('01') Then
         $iCheck = MouseGetPos()
         If $iCheck[0] = $iPos[0] And $iCheck[1] = $iPos[1] Then
             MsgBox(0,'','Double Clicked'
         Endif
     EndIf
     WEnd
Endif

No shorter way i know of.

 

Link to comment
Share on other sites

39 minutes ago, DynamicRookie said:
If _IsPressed('01') Then
     $iPos = MouseGetPos()
     While 1
     If _IsPressed('01') Then
         $iCheck = MouseGetPos()
         If $iCheck[0] = $iPos[0] And $iCheck[1] = $iPos[1] Then
             MsgBox(0,'','Double Clicked'
         Endif
     EndIf
     WEnd
Endif

No shorter way i know of.

 

Sorry, your code didn't work for me.

The code below works and counts all single clicks and double clicks but it counts the single clicks that comes as part of the double clicks too.

#Include <Misc.au3> ; Used for the _IsPressed
 HotKeySet("{ESC}", "_ExitScript") ;Hot key Esc to Exit script
 $nCountSingleClick = 0 ;Left click count
 $nCountDoubleClick = 0 ;Double Click count
 $PreX = 0 ;Previous X
 $PreY = 0 ;Previous Y
 $hTimer = TimerInit() ;Start timer
 While 1 ; Loop until user presses ESc to exit the Recorder
        If _IsPressed("01") then ; If left mouse is pushed.
            While (_IsPressed("01")) ;Wait until user releases button
                ;Sleep(100)
            WEnd
            $pos = MouseGetPos() ; Get the position.
            $nTimeDelay = Int(TimerDiff($hTimer)) + 1 ;Get the delay in milli seconds
            $hTimer = TimerInit() ;Start the timer again
            If $PreX = $pos[0] and $PreY = $pos[1]  and $nTimeDelay < 500 Then  ;If two consecutive clicks are made on the same position with a delay leass than 500 ms
                $nCountDoubleClick = $nCountDoubleClick + 1
                ToolTip ($nCountDoubleClick & ") " & "Double Click X: " & $pos[0] & ', Y: ' & $pos[1]) ;Double click
            Else
                $nCountSingleClick = $nCountSingleClick + 1
                ToolTip($nCountSingleClick & ") " & 'Left Clicked X: ' & $pos[0] & ', Y: ' & $pos[1])
                $PreX = $pos[0]
                $PreY = $pos[1]
            EndIf
        EndIf
 WEnd
Func _ExitScript()
    Exit
EndFunc ;=> _ExitScript

 

Link to comment
Share on other sites

Hello,

try this

Spoiler
#include <Misc.au3>

HotKeySet("{ESC}", "_ExitScript")

Const $maxDCT = 500 ; max. Doubleclicktime (ms)

Local $hDLL = DllOpen("user32.dll")
Local $LCTimer = TimerInit() ; Leftclick Timer

While True
    If _IsPressed("01", $hDLL) Then checkLeftClick()
WEnd

DllClose($hDLL)


Func checkLeftClick()
    Local $bDC = False ; DoubleClick?

    Local $ClickDelay = TimerInit()
    Local $PrePos = MouseGetPos()

    While (_IsPressed("01", $hDLL)) ; Wait until user releases button
    WEnd

    While (TimerDiff($ClickDelay) < $maxDCT)

        If _IsPressed("01", $hDLL) Then
            Local $Pos = MouseGetPos()

            If ((TimerDiff($ClickDelay) < $maxDCT) And ($PrePos[0] = $Pos[0]) And ($PrePos[1] = $Pos[1])) Then
                $bDC = True
                ExitLoop
            EndIf
        EndIf
    WEnd

    While (_IsPressed("01", $hDLL)) ; Wait until user releases button
    WEnd

    If $bDC Then
        ConsoleWrite("Doubleclick (left," & $PrePos[0] & "," & $PrePos[1] & ")" & @CRLF)
    Else
        ConsoleWrite("Click (left," & $PrePos[0] & "," & $PrePos[1] & ")" & @CRLF)
    EndIf

    Return $bDC
EndFunc   ;==>checkLeftClick

Func _ExitScript()
    Exit
EndFunc   ;==>_ExitScript

 

 

Edited by bernd670

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

Here is another one for you  to try :

#include <Misc.au3> ; Used for the _IsPressed
HotKeySet("{ESC}", "_ExitScript") ;Hot key Esc to Exit script

$nCountSingleClick = 0 ;Left click count
$nCountDoubleClick = 0 ;Double Click count

$hDLL = DllOpen("user32.dll")
OnAutoItExitRegister('_DllClose')

$Clicks = 0
$DblClickSpeed = 200

While 1 ; Loop until user presses ESc to exit the Recorder
    If _IsPressed("01") Then ; If left mouse is pushed.
        $hTimer = TimerInit() ;Start the timer again
        $Clicks += 1
        $pos = MouseGetPos() ; Get the position.
        If $Clicks >= 2 Then
            $Clicks = 0
            $nCountDoubleClick += 1
            ToolTip($nCountDoubleClick & ") " & "Double Click X: " & $pos[0] & ', Y: ' & $pos[1]) ;Double click
        EndIf

        While (_IsPressed("01")) ;Wait until user releases button
            Sleep(10)
        WEnd
    EndIf

    If $Clicks And Int(TimerDiff($hTimer)) > $DblClickSpeed Then
        $Clicks = 0
        $nCountSingleClick += 1
        ToolTip($nCountSingleClick & ") " & 'Single Click X: ' & $pos[0] & ', Y: ' & $pos[1])
    EndIf
WEnd

Func _ExitScript()
    Exit
EndFunc   ;==>_ExitScript

Func _DllClose()
    DllClose($hDLL)
EndFunc   ;==>_DllClose

 

Edited by Deye
Link to comment
Share on other sites

Hi,

Here comes my version with detecting any number of continuous short clicks on a same position. 

Thank you so much for your help friends :-)

#Include <Misc.au3> ; Used for the _IsPressed
HotKeySet("{ESC}", "_ExitScript") ;Press Ecs key to Exit script
Local $hDLL = DllOpen("user32.dll") ; Dll as calling _IsPressed function repeatedly
While 1
    $nLeftclicks = 0 ;Initialize left click count on each iteration
    If _IsPressed("01", $hDLL) Then ;If left mouse button pressed
        $Pos = MouseGetPos() ;Get mouse position
        Do
            While (_IsPressed("01", $hDLL)) ;Wait until user releases button
                Sleep(10)
            WEnd
            $nLeftclicks += 1 ;Increment click count
            sleep(100) ;Wait for 100ms
            $aTemp = MouseGetPos() ;Get new mouse position again
        Until(Not ($aTemp[0] = $Pos[0] and $aTemp[1] = $Pos[1] and _IsPressed("01", $hDLL))) ;Loop until mouse is on a new position or it is not pushed again
        ToolTip("X: " & $Pos[0] & "Y: " & $Pos[1] & "Number of continous clicks: " & $nLeftclicks)
        ConsoleWrite("X: " & $Pos[0] & "Y: " & $Pos[1] & "Number of continous clicks: " & $nLeftclicks & @crlf)
    EndIf
Wend

Func _ExitScript()
    DllClose($hDLL)
    Exit
EndFunc ;=> _ExitScript

 

Link to comment
Share on other sites

  • PoojaKrishna changed the title to [SOLVED] Detect Double Click

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

×
×
  • Create New...