Sign in to follow this  
Followers 0
FunkyBunnies

Record mouse movement?

3 posts in this topic

Hey all,

I was toying with an idea using a captured mouse action and I was wondering if you guys had any ideas? :D

Basically to click and drag and have autoit recreate this mouse stroke. I'm aware of AU3Record.exe in AutoIt3\SciTE\ScriptWriter

so I imagine it's possible, but I'm not sure how one would go about it?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Probably using a low-level mouse hook procedure and a temporary file or variable. For example you can do something like this in the hook procedure:

Global Const $tagMSLLHOOKSTRUCT = _
    $tagPOINT & 
    ';dword mouseData;' & _
    'dword flags;' & _
    'dword time;' & _
    'ulong_ptr dwExtraInfo'

Global $sWrite = ''
Global $fClicked = False
Global $iX1 = 0, $iY1 = 0
Global $iX2 = -1, $iY2 = -1
Global $hFile = FileOpen($sFile, 2)
.
.
.


Func MouseHook($iCode, $iwParam, $ilParam)
    Local $tMSLLHOOKSTRUCT
    Local $iX, $iY
    
    If $iCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    EndIf
    
    $tMSLLHOOKSTRUCT = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam)
    $iX = DllStructGetData($tMSLLHOOKSTRUCT, 'X')
    $iY = DllStructGetData($tMSLLHOOKSTRUCT, 'Y')

    Switch $iwParam
        Case $WM_MOUSEMOVE
            If $fClicked Then
                $iX2 = $iX
                $iY2 = $iY
            Else
                $iX2 = -1
                $iY2 = -1
            EndIf
            
        Case $WM_LBUTTONDOWN
            $fClicked = True
            $iX1 = $iX
            $iY1 = $iY
            $iX2 = -1
            $iY2 = -1
        
        Case $WM_LBUTTONUP
            $fClicked = False
            If $iX2 = -1 Then
                $sWrite = 'MouseClick("left", ' & $iX & ', ' & $iY & ')'
            Else
                $sWrite = 'MouseClickDrag("left", ' & $iX1 & ', ' & $iY1 & ', ' & $iX2 & ', ' & $iY2 & ')'
            EndIf
            FileWrite($hFile, $sWrite & @CRLF)
    EndSwitch
        
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

The hook procedure is not notified about WM_LBUTTONDBLCLK or WM_RBUTTONDBLCLK so you need to use GetDoubleClickTime to get this value and see if it's a double click event. If so you'll need to previously write to the variable a MouseClick for example with 1 click but change it to 2 if it's a double click event.

Edited by Authenticity

Share this post


Link to post
Share on other sites

Awesome, thanks for the help Authenticity ^_^

I'll play around with it

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  
Followers 0