Jump to content
Sign in to follow this  

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?



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




EndFunc ;==>_LeftClick




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

Share this post

Link to post
Share on other sites

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

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

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
    $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")

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

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

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.