Jump to content

Distinguishing Between Click and Drag


Recommended Posts

I have a script where I want a left click to do something different than a left click and hold, drag. I already have the RMB with another command so they cannot be separated in that manner.

The following code is how I have distinguished the two, but it isn't 100% foolproof. Is there a better way?

CODE

;---SNIP!

Func _LeftClick()

Local $nCID=@GUI_CtrlId

Local $arTemp=MouseGetPos()

Sleep(75) ;<----- THIS COULD BE A SETTING, I GUESS???

Local $Temp=GUIGetCursorInfo() ;after sleep - if the primary button is still down, then cursor is moving

If $Temp[2]=1 Then

_Move($nCID, $arTemp) ;send ctrlId and original mouse position

Else

_Rotate($nCID)

EndIf

EndFunc ;==>_LeftClick

;---SNIP!

Thanks,

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

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

$Form1 = GUICreate("Form1", 633, 452, 193, 125)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $ans = mousetest()
; returns -1 if mousetest() finds mouse button not down
    If $ans = 1 Then MsgBox(0, "", "mouse dragged")
    If $ans = 0 Then MsgBox(0, "", "mouse clicked")
WEnd

Func mousetest()
    $cur_info = GUIGetCursorInfo($Form1)
    If $cur_info[2] = 0 Then Return -1; mouse not down
    Do
        $cur_info2 = GUIGetCursorInfo($Form1)
        If $cur_info2[2] = 0 Then Return 0; mouse clicked
        Sleep(50)
    Until $cur_info[0] <> $cur_info2[0] Or $cur_info[1] <> $cur_info2[1]
    Return 1; dragged mouse
EndFunc;==>mousetest

hope it is what your after .

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

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...