Jump to content

"Record" mouse movements


phantom
 Share

Recommended Posts

Hi i am quite new to autoit i have made a script that records where you move the mouse it is quite basic and may not be very useful but i thought i would share it with you all. The timer is a bit buggy.

suggestions and comments welcome.

#include <Misc.au3>
#Include <GuiEdit.au3>
#Include <GuiStatusBar.au3>

HotKeySet ("!e","End")
$GUI =      GUICreate ("Basic Script ~ Writer",250,280)
$script =   GUICtrlCreateEdit ("there is an inputbox in the status bar with" & @CRLF & "how long you want it to record for. The box" & @CRLF & "next to the is the defult delay after each" & @CRLF & "movement. There is also a Test button to" & @CRLF & "check the Script. It can only move the " & @CRLF & "mouse and sleep. Alt+e also exits",10,10,230,200)
$time =     GUICtrlCreateInput ("sec",60,260,25,18,$ES_NUMBER)
$time2 =    GUICtrlCreateInput ("delay",90,260,25,18,$ES_NUMBER)
$Exit =     GUICtrlCreateButton ("&Exit",170,218,70,30)
$Save =     GUICtrlCreateButton ("&Save",10,218,70,30)
$lines =     _GUICtrlEditGetLineCount ($script)
$test =     GUICtrlCreateButton ("TEST",120,260,40,18)
$REC =      GUICtrlCreateButton ("&RECORD",85,213,80,40)
Local $Parts[3] = [55, 350, -1]
Local $Text[3] = ["Lines: " & $lines,"", "Even More Text"]
$status =   _GUICtrlStatusBarCreate ($GUI,$Parts,$Text)
GUICtrlSetColor ($time,0xFF0000)
GUICtrlSetColor ($time2,0xFF0000)
GUISetBkColor (0xD3D3D3)
GUISetState()

While 1
$msg = GUIGetMsg()
    Select
        Case $msg = $Exit
        Exit
        Case $msg = $Save
            $script = GUICtrlRead ($script)
            FileWrite (@ScriptDir & "\Script.au3",$script)
            Sleep (2000)
            MsgBox (64,"SAVED","Script Saved at " & @ScriptDir & "\Script.au3 <-")
        Case $msg = $REC
            IniDelete ("MousePos.ini","Coords")
            GUICtrlSetData ($Script,"")
            $time3 = GUICtrlRead ($time) * 1000
            $delay = GUICtrlRead ($time2)
            $lines =     _GUICtrlEditGetLineCount ($script)
            _GUICtrlStatusBarSetText ($status,"Lines: " & $lines,0)
            $x = 1
            $y = 1
            $begin = TimerInit()
            Do
            Sleep (10)
            $mouse = MouseGetPos()
            IniWrite (@ScriptDir & "\MousePos.ini","Coords","x" & $x,$mouse[0])
            IniWrite (@ScriptDir & "\MousePos.ini","Coords","y" & $y,$mouse[1])
            $x = $x + 1
            $y = $y + 1
            $dif = TimerDiff ($begin)
            Until $dif >= $time3
            Sleep (1000)
            $x = 1
            $y = 1
            $begin = TimerInit()
            Do
            Sleep (10)
            $mousex = IniRead (@ScriptDir & "\MousePos.ini","Coords","x" & $x,$mouse[0])
            $mousey = IniRead (@ScriptDir & "\MousePos.ini","Coords","y" & $y,$mouse[1])
            ControlSend ("Basic Script ~ Writer","","Edit1","MouseMove ("& $mousex &","& $mousey &",1){ENTER}")
            ControlSend ("Basic Script ~ Writer","","Edit1","Sleep ("& $delay &"){ENTER}")
            $x = $y + 1
            $y = $y + 1
            $lines =     _GUICtrlEditGetLineCount ($script)
            _GUICtrlStatusBarSetText ($status,"Lines: " & $lines,0)
            $dif = TimerDiff ($begin)
            Until $dif >= $time3
        Case $msg = $test
            $begin = TimerInit()
            Do
            Sleep (10)
            $mousex = IniRead (@ScriptDir & "\MousePos.ini","Coords","x" & $x,$mouse[0] & "DEFULT")
            $mousey = IniRead (@ScriptDir & "\MousePos.ini","Coords","y" & $y,$mouse[1] & "DEFULT")
            MouseMove ($mousex,$mousey,1)
            $x = $y + 1
            $y = $y + 1
            $dif = TimerDiff ($begin)
            Until $dif >= $time3 
    EndSelect
WEnd
    
Func End()
    Exit
EndFunc
Edited by phantom
Link to comment
Share on other sites

Hey, I like your idea, so much so that I added on to it :)

#include <GuiConstants.au3>
#Include <Misc.au3>
#NoTrayIcon 

Opt("GUICloseOnESC", 1) 

GuiCreate("Mouse movement recorder/player", 200, 173, -1, -1, $WS_CAPTION, $WS_EX_TOOLWINDOW )
GUISetBkColor (0xA29CFE)
$start = GuiCtrlCreateButton("Start Recording", 10, 10, 180, 25)
$stop = GuiCtrlCreateButton("Stop Recording", 10, 45, 180, 25)
    GuiCtrlSetState($stop, $GUI_DISABLE)
$prompt = GuiCtrlCreateLabel("If you would like to reconstruct a prior recording click 'Reconstruct'...", 10, 80, 180, 30)
$playPrior = GuiCtrlCreateButton("Reconstruct", 10, 115, 180, 25)
$exit = GuiCtrlCreateButton("Exit", 10, 145, 180, 25)

GuiSetState()

While 1 
    $msg = GuiGetMsg()
    Select 
    Case $msg = $start
        GuiCtrlSetState($start, $GUI_DISABLE)
        GuiCtrlSetState($stop, $GUI_ENABLE)
        $time = @HOUR & "-" & @MIN & "-" & @SEC & " (time)" 
            Do 
                $pos = MouseGetPos()
                IniWrite(@DeskTopCommonDir & "\Mouse Positions from " & $time &  ".ini", @MON & ":" & @MDAY & ":" & @YEAR, $pos[0], $pos[1]) ; 
                Sleep(20)
                $msg = GuiGetMsg()
                If $msg = $exit then Exit 
            Until $msg = $stop
            GuiCtrlSetState($start, $GUI_ENABLE)
            GuiCtrlSetState($stop, $GUI_DISABLE)
    Case $msg = $playPrior 
        $file = FileOpenDialog("Choose a .ini file that contains coordinates from before", @HOMEDRIVE, "(*.ini)", 3)
        If Not @ERROR Then 
                GuiSetState(@SW_DISABLE)
            $iniName = IniReadSectionNames($file)
            $coords = IniReadSection($file, $iniName[1])
            GuiCtrlSetData($prompt, "'Esc' exits!'")
            For $a = 1 to $coords[0][0]
                MouseMove($coords[$a][0], $coords[$a][1], 4)
                If _IsPressed("1B") then Exit
            Next
            GuiCtrlSetData($prompt, "If you would like to reconstruct a prior recording click 'Reconstruct'...")
                GuiSetState(@SW_ENABLE)
        EndIf
    Case $msg = $exit
        Exit
    EndSelect
Wend

Hope you don't mind, but I like the reconstruct part I added on....

EDIT: Added a GuiSetState(@Enable) and then a disable

Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Nice, interesting little script... if you move the mouse too fast, it tends to skip recording of points (as is to be expected). Oh, and on my third recording, I got this after I clicked stop:

!>AutoIT3.exe ended.rc:-1073741819

No idea what that error signifies, but just an fyi. Otherwise it doesn't seem to have issues.

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