Jump to content

Monitor mouse click, drag&drop, no hook, no blocking


queensoft
 Share

Recommended Posts

Using standard _IsPressed function.

Quick and dirty.

 

#include <Misc.au3>

Opt("MouseClickDownDelay", 0)
Opt("MouseClickDownDelay", 0)
Opt("MouseClickDragDelay", 0)


HotKeySet("+{ESC}", "Terminate")


Global $click = False   ; variable to keep if mouse left still pressed (for drag&drop)
Global $pos01[2]=[-1,-1]    ; drag start position / left click position
Global $pos02[2]=[-1,-1]    ; drop end position

while 1
    if (_IsPressed(01)) Then    ; left mouse click
        if (not($click)) Then   ; if not clicked = first click
            $pos01 = MouseGetPos()  ; record position
            $click = True   ; mouse is clicked
            Sleep(1)
        EndIf

        While _IsPressed("01")  ; while left mouse clicked, just repeat
            Sleep(1)
        WEnd

    EndIf

        $pos02 = MouseGetPos()  ; get end position

        If ($pos01[0]<>$pos02[0]) or ($pos01[1]<>$pos02[1]) And ($pos01[0]<>-1) and ($pos01[1]<>-1)  Then   ; compare start / end positions, at least 2 different = drag&drop
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Drag & drop from ' & $pos01[0] & "x" & $pos01[1] & " to " & $pos02[0] & "x" & $pos02[1] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

            $pos01[0]=-1    ; reset all values
            $pos01[1]=-1
            $pos02[0]=-1
            $pos02[1]=-1
            $click = False
        EndIf

        If ($pos01[0]=$pos02[0]) and ($pos01[1]=$pos02[1]) And ($pos01[0]<>-1) and ($pos01[1]<>-1)  Then    ; compare start / end positions, if equal = left click
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Click at ' & $pos01[0] & "x" & $pos01[1] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

            $pos01[0]=-1    ; reset all values
            $pos01[1]=-1
            $pos02[0]=-1
            $pos02[1]=-1
            $click = False
        EndIf

    sleep(1)
wend


Func Terminate()
    MsgBox(0, "End", "End", 2)
    Exit
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

×
×
  • Create New...