PoojaKrishna Posted April 15, 2018 Posted April 15, 2018 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
DynamicRookie Posted April 15, 2018 Posted April 15, 2018 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.
PoojaKrishna Posted April 15, 2018 Author Posted April 15, 2018 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
bernd670 Posted April 15, 2018 Posted April 15, 2018 (edited) Hello, try this Spoiler expandcollapse popup#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 April 15, 2018 by bernd670 KeeperOfTheReaper and PoojaKrishna 1 1 greetingsbernd I hacked 127.0.0.1 ->
Deye Posted April 15, 2018 Posted April 15, 2018 (edited) Here is another one for you to try : expandcollapse popup#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 April 15, 2018 by Deye PoojaKrishna 1
PoojaKrishna Posted April 16, 2018 Author Posted April 16, 2018 @bernd670 and @Deye , Thank you so much. Both the scripts work perfect.
PoojaKrishna Posted April 17, 2018 Author Posted April 17, 2018 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
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