Jump to content



Photo

Capture Mouse Path and Play it.


  • This topic is locked This topic is locked
14 replies to this topic

#1 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 04 May 2009 - 05:37 PM

Hello,

I was a little bored today and I came up with this. Mayby it could be usefull for someone. ^_^

Note: (Human playback speed)
$fDelay = 50
$fSpeed = 1


Code
AutoIt         
#include-once #include <Misc.au3> ; #FUNCTION# ================================================================================================= ; Name...........: _Mouse_Capture() ; Description ...: Captures the x and y pos for a given time. ; Syntax.........: _Mouse_Capture($fTime, $fDelay = 10) ; Parameters ....:  $fTime = For how long it should capture the movind mouse (Time in seconds). ;                   $fDelay = The capture delay (Default = 10). ; Errors ........: - ; Return values .: $_Return ; Author ........: Almar Mulder (AlmarM) ; Modified.......: - ; Remarks .......: - ; Related .......: _Mouse_Play() ; Link ..........: - ; Example .......: Yes ; #FUNCTION# ================================================================================================= Func _Mouse_Capture($fTime, $fDelay = 10)     Local $_PosX, $_PosY     Local $_fDown[2] = [0, 0]     Local $_Return[2]         $_Start = TimerInit()     Do         $_Stop = TimerDiff($_Start)         $_GetPos = MouseGetPos()         $_PosX &= $_GetPos[0] & ","         $_PosY &= $_GetPos[1] & ","                 If _IsPressed("01") Then             If $_fDown[0] = 0 Then                 $_PosX &= $_GetPos[0] & "ld,"                 $_PosY &= $_GetPos[1] & "ld,"                 $_fDown[0] = 1             EndIf         Else             If $_fDown[0] = 1 Then                 $_PosX &= $_GetPos[0] & "lu,"                 $_PosY &= $_GetPos[1] & "lu,"                 $_fDown[0] = 0             EndIf         EndIf                 If _IsPressed("02") Then             If $_fDown[1] = 0 Then                 $_PosX &= $_GetPos[0] & "rd,"                 $_PosY &= $_GetPos[1] & "rd,"                 $_fDown[1] = 1             EndIf         Else             If $_fDown[1] = 1 Then                 $_PosX &= $_GetPos[0] & "ru,"                 $_PosY &= $_GetPos[1] & "ru,"                 $_fDown[1] = 0             EndIf         EndIf                 Sleep($fDelay)     Until $_Stop >= $fTime * 1000         $_Return[0] = $_PosX     $_Return[1] = $_PosY     Return $_Return EndFunc ; #FUNCTION# ================================================================================================= ; Name...........: _Mouse_Play() ; Description ...: Plays the captured mouse path. ; Syntax.........: _Mouse_Play($fCapture, $fSpeed = 1) ; Parameters ....:  $fCapture = The captured _Mouse_Capture variable. ;                   $fSpeed = The speed the mouse should move (Default = 1). ; Errors ........: - ; Return values .: - ; Author ........: Almar Mulder (AlmarM) ; Modified.......: - ; Remarks .......: - ; Related .......: _Mouse_Capture() ; Link ..........: - ; Example .......: Yes ; #FUNCTION# ================================================================================================= Func _Mouse_Play($fCapture, $fSpeed = 1)     $_Trim_x = StringTrimRight($fCapture[0], 1)     $_Trim_y = StringTrimRight($fCapture[1], 1)         $_Split_x = StringSplit($_Trim_x, ",")     $_Split_y = StringSplit($_Trim_y, ",")         $_Max = $_Split_x[0]         For $_i = 1 To $_Max         MouseMove($_Split_x[$_i], $_Split_y[$_i], $fSpeed)         If StringRight($_Split_x[$_i], 2) = "ld" Then MouseDown("left")         If StringRight($_Split_x[$_i], 2) = "lu" Then MouseUp("left")         If StringRight($_Split_x[$_i], 2) = "rd" Then MouseDown("right")         If StringRight($_Split_x[$_i], 2) = "ru" Then MouseUp("right")     Next EndFunc


Example
$Var = _Mouse_Capture(5) _Mouse_Play($Var)


Tell me what you think. ;)

Update:
- Added mouseclick capture

- Added mouseup and down capture - (WideBoyDixon)

AlmarM

Edited by AlmarM, 05 May 2009 - 06:35 PM.








#2 UEZ

UEZ

    Never say never

  • MVPs
  • 3,616 posts

Posted 04 May 2009 - 06:38 PM

Funny idea ^_^

Thanks!


UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#3 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 04 May 2009 - 10:14 PM

Nice idea. Perhaps it would be better if it captured mouse clicks too?

^_^

WBD

#4 Skrip

Skrip

    Psychonaut

  • Active Members
  • PipPipPipPipPipPip
  • 2,340 posts

Posted 05 May 2009 - 01:57 AM

Very nice! Mouse clicks would be nice though.

We're trapped in the belly of this horrible machine.And the machine is bleeding to death...


#5 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 05 May 2009 - 08:20 AM

Hmm yeah, mouse clicks. Ill try adding it. Thanks! ^_^

AlmarM

EDIT: Added mouseclicks. View first post!

Any more ideas?

Edited by AlmarM, 05 May 2009 - 08:34 AM.


#6 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 05 May 2009 - 08:56 AM

Rather than MouseClick, perhaps you could use MouseDown/MouseUp so that I could capture and reply drag-and-drop?

WBD

#7 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 05 May 2009 - 01:19 PM

Rather than MouseClick, perhaps you could use MouseDown/MouseUp so that I could capture and reply drag-and-drop?

WBD

Do you have any ideas how to record the mousedown / up? And even playback?

AlmarM

#8 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 05 May 2009 - 02:01 PM

Something like this?:

AutoIt         
#include-once #include <Misc.au3> ; #FUNCTION# ================================================================================================= ; Name...........: _Mouse_Capture() ; Description ...: Captures the x and y pos for a given time. ; Syntax.........: _Mouse_Capture($fTime, $fDelay = 10) ; Parameters ....:  $fTime = For how long it should capture the movind mouse (Time in seconds). ;               $fDelay = The capture delay (Default = 10). ; Errors ........: - ; Return values .: $_Return ; Author ........: Almar Mulder (AlmarM) ; Modified.......: - ; Remarks .......: - ; Related .......: _Mouse_Play() ; Link ..........: - ; Example .......: Yes ; #FUNCTION# ================================================================================================= Func _Mouse_Capture($fTime, $fDelay = 10)     Local $_PosX, $_PosY     Local $_fDown[2] = [0, 0]     Local $_Return[2]         $_Start = TimerInit()     Do         $_Stop = TimerDiff($_Start)         $_GetPos = MouseGetPos()         $_PosX &= $_GetPos[0] & ","         $_PosY &= $_GetPos[1] & ","                 If _IsPressed("01") Then             If $_fDown[0] = 0 Then                 $_PosX &= $_GetPos[0] & "ld,"                 $_PosY &= $_GetPos[1] & "ld,"                 $_fDown[0] = 1             EndIf         Else             If $_fDown[0] = 1 Then                 $_PosX &= $_GetPos[0] & "lu,"                 $_PosY &= $_GetPos[1] & "lu,"                 $_fDown[0] = 0             EndIf         EndIf                 If _IsPressed("02") Then             If $_fDown[1] = 0 Then                 $_PosX &= $_GetPos[0] & "rd,"                 $_PosY &= $_GetPos[1] & "rd,"                 $_fDown[1] = 1             EndIf         Else             If $_fDown[1] = 1 Then                 $_PosX &= $_GetPos[0] & "ru,"                 $_PosY &= $_GetPos[1] & "ru,"                 $_fDown[1] = 0             EndIf         EndIf                 Sleep($fDelay)     Until $_Stop >= $fTime * 1000         $_Return[0] = $_PosX     $_Return[1] = $_PosY     Return $_Return EndFunc ; #FUNCTION# ================================================================================================= ; Name...........: _Mouse_Play() ; Description ...: Plays the captured mouse path. ; Syntax.........: _Mouse_Play($fCapture, $fSpeed = 1) ; Parameters ....:  $fCapture = The captured _Mouse_Capture variable. ;               $fSpeed = The speed the mouse should move (Default = 1). ; Errors ........: - ; Return values .: - ; Author ........: Almar Mulder (AlmarM) ; Modified.......: - ; Remarks .......: - ; Related .......: _Mouse_Capture() ; Link ..........: - ; Example .......: Yes ; #FUNCTION# ================================================================================================= Func _Mouse_Play($fCapture, $fSpeed = 1)     $_Trim_x = StringTrimRight($fCapture[0], 1)     $_Trim_y = StringTrimRight($fCapture[1], 1)         $_Split_x = StringSplit($_Trim_x, ",")     $_Split_y = StringSplit($_Trim_y, ",")         $_Max = $_Split_x[0]         For $_i = 1 To $_Max         MouseMove($_Split_x[$_i], $_Split_y[$_i], $fSpeed)         If StringRight($_Split_x[$_i], 2) = "ld" Then MouseDown("left")         If StringRight($_Split_x[$_i], 2) = "lu" Then MouseUp("left")         If StringRight($_Split_x[$_i], 2) = "rd" Then MouseDown("right")         If StringRight($_Split_x[$_i], 2) = "ru" Then MouseUp("right")     Next EndFunc


WBD

#9 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 05 May 2009 - 06:37 PM

Added mousedown and up! View first post!

AlmarM

#10 UEZ

UEZ

    Never say never

  • MVPs
  • 3,616 posts

Posted 05 May 2009 - 08:09 PM

One suggestion to avoid high cpu load when play back mouse movements:

add a Sleep(20) to the for...next loop in function Func _Mouse_Play($fCapture, $fSpeed = 1).

UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#11 whitegod

whitegod

    Seeker

  • New Members
  • 1 posts

Posted 01 June 2009 - 09:23 PM

Great,Thanks for sharing

#12 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,337 posts

Posted 14 November 2012 - 06:11 PM

One suggestion to avoid high cpu load when play back mouse movements

Sleep wouldnt be alone able to reduce much the CPU load
Hence
a MouseHook would be more efficient
PredictText: Predict Text of an Edit Control Like Scite. | Remote Gmail: Execute your Scripts through Gmail. | StringRegExp: Share and learn RegExp. | Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). | Database: An easier approach for _SQ_LITE beginners. | MathsEx: A UDF for Fractions and LCM, GCF/HCF. | FloatingText: An UDF for make your text floating. | Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead.

#13 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 14 November 2012 - 06:23 PM

PhoenixXL,

And you think it was worth necro-posting after 3 1/2 years to say that? :huh:

Guess what? I do not, so please think twice before posting next time. :naughty:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#14 techbard

techbard

    Seeker

  • Active Members
  • 11 posts

Posted 15 November 2012 - 04:26 AM

How about adding import/export text command file?

like this...

mousemove(0, 0)
mousemove(1, 0)
mousemove(2, 0)
mousemove(3, 0)
...
sleep(300)

:)

#15 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,387 posts

Posted 15 November 2012 - 08:11 AM

techbard,

What part of my previous post was not clear? Do NOT necro-post again! :naughty:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users