AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AHK MouseRecorder (MoRe)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
garath



Joined: 24 Mar 2005
Posts: 372
Location: germany

PostPosted: Thu Feb 08, 2007 4:12 pm    Post subject: AHK MouseRecorder (MoRe) Reply with quote

AHK MouseRecorder (MoRe)


Today I want to present a funny little tool, the mouse recorder. I hope it is the first mouserecorder and nobody scripted such a tool in AHK, before;-)
Last week i read the thread about the new advanced AHK ScriptWriter, it will be the most important tool in Autohotkey, because it is the first thing a new user will test. If the script writer works well we will get lots of new members in our community. Inspired by the scriptwriter I thought about a Mouse-movement-recorder, which records and replays realtime, so you
can watch the mouse moving, as you did move your mouse in the record mode. At the moment, Mousewheel, left and right button and the movement is recorded. Mouseclicks and wheel are send normal, no controlsend implemented right now. Coordinates are sent relative to the desktop (screen-mode).

The script starts recording by pressing F1, and stops with F2. Replay starts with F3. There is no Gui till now, I wrote the script to test the possibilities Wink
Each 15ms mouse position and keystates of the buttons + wheel are checked. If any Parameter changes, the new parameters are written to a textfile, including the time since start of recording, and the ID of the Window under the mouse.
In replay mode, each 15ms is checked, if the time from a counter reaches the time of the recorded next Dataset. If so, the Dataset is send to the mouse, and the mouse is moved accordingly. At the beginning of the Replay, the same window is activated, as it was active at the beginning of the recording.

I tested it with MS_Paint, I drew a little picture, and replayed it, you can see the two testimages, below.




Missing features:
a nice Gui
scalable replay-speed
recording of additional mouse-Buttons (xbutton1 and xbutton2)
recording of a Joystick
recording of keybord-buttons
export-function to build a standalone AHKscript from the recorded mousemovements
usage of controlsend
support screen and relative Coordmode
documentation in the code

Code:

;***********************************************
;**                                           **
;**  Mouse movement recorder (MoRe) 0.1       **
;**  based on the idea of AHK script writer   **
;**  written by garath                        **
;**                                           **
;***********************************************

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#Persistent
CoordMode, Mouse, Screen
SetBatchLines, -1


;*************************************+*********
;**                                           **
;**           F1 Start recording              **
;**           F2 Stop  recording              **
;**           F3 Replay                       **
;**                                           **
;***********************************************


~WheelDown::Wheel_down += A_EventInfo
~Wheelup::Wheel_up += A_EventInfo


f1::
  FileDelete, Mausbewegungen.txt
  Mouse_moves =
  Wheel_up =
  Wheel_down =
  Time_old := A_TickCount
  SetTimer, WatchMouse, Off
  SetTimer, WatchMouse, 10
  SetTimer, WatchMouse, on
Return

f2::
  SetTimer, WatchMouse, Off
  ToolTip
Return

f3::Gosub, replay

Return


;******************************************

WatchMouse:
  Time_Index := A_TickCount - Time_old
  MouseGetPos, xpos, ypos, id, Control
  GetKeyState, lButt, LButton
  GetKeyState, mButt, MButton
  GetKeyState, rButt, RButton
  Mouse_Data = %xpos%|%ypos%|%lButt%|%mButt%|%rButt%|%Wheel_up%|%Wheel_down%|%ID%|%Time_Index%`n
  ToolTip, recording
  If (xpos<>xpos_old OR ypos<>ypos_old OR Wheel_up OR Wheel_down OR lButt<>Lbutt_old OR mButt<>mButt_old OR

rButt<>rButt_old)
    {
      FileAppend, %Mouse_data%, Mausbewegungen.txt
      xpos_old  := xpos
      ypos_old  := ypos
      lButt_old := lButt
      mButt_old := mButt
      rButt_old := rButt
      Wheel_up =
      Wheel_down =
    }
Return

;*******************************************

replay:
  FileRead,Mouse_moves, Mausbewegungen.txt
  StringReplace, Mouse_data, Mouse_moves, `n, @, All
  StringSplit, Mouse_data_, Mouse_data , @
  Loop, %Mouse_data_0%
      StringSplit, Mouse_data_%A_Index%_, Mouse_data_%A_Index% ,|
  Data_Index = 1
  Data_Index_old := 1
  id := Mouse_data_1_8
  WinActivate, ahk_id %id%
  Time_old := A_TickCount
  SetTimer, Replaytimer, Off
  SetTimer, Replaytimer, 10
  SetTimer, Replaytimer, on
Return

;********************************************

replaytimer:
  Time_Index := A_TickCount - Time_old
  Mouse_data_%Data_Index%_9 += 0

  If (Time_Index > Mouse_data_%Data_Index%_9)
    {
      MouseMove, Mouse_data_%Data_Index%_1, Mouse_data_%Data_Index%_2
      lButt := Mouse_data_%Data_Index%_3
      mButt := Mouse_data_%Data_Index%_4
      rButt := Mouse_data_%Data_Index%_5
      wheel_up := Mouse_data_%Data_Index%_6
      wheel_down := Mouse_data_%Data_Index%_7

      If (Mouse_data_%Data_Index_old%_3 <> Mouse_data_%Data_Index%_3)
          MouseClick , Left ,,,,, %lButt%
      If (Mouse_data_%Data_Index_old%_4 <> Mouse_data_%Data_Index%_4)
          MouseClick , middle ,,,,, %mButt%
      If (Mouse_data_%Data_Index_old%_5 <> Mouse_data_%Data_Index%_5)
          MouseClick , Right ,,,,, %rButt%
      If (Mouse_data_%Data_Index%_6)
          MouseClick, WheelUp, , , %wheel_up%       
      If (Mouse_data_%Data_Index%_7)
          MouseClick, Wheeldown, , , %wheel_down%       

      Data_Index_old := Data_Index
      Data_Index += 1
      If (Data_Index = Mouse_data_0)
        {
          SetTimer Replaytimer, Off
          Data_Index = 0
        }
    }
;  x := Mouse_data_%Data_Index%_9
;  tooltip %Time_Index%_%A_TickCount% - %Time_old% __%x%

Return



Maybe, next week I can present the "MoRe Joy" Wink

**garath walks away, searching his 10 Years old analog Jostick Wink**


Last edited by garath on Thu Feb 08, 2007 4:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Thu Feb 08, 2007 4:15 pm    Post subject: Reply with quote

So give us some MoRe, dude ! Laughing
Back to top
Guest






PostPosted: Thu Feb 08, 2007 4:25 pm    Post subject: Reply with quote

wow......
Back to top
garath



Joined: 24 Mar 2005
Posts: 372
Location: germany

PostPosted: Thu Feb 08, 2007 5:07 pm    Post subject: Reply with quote

Thanks, Bobo and guest Cool

Btw, long time ago I saw somebody using a transparent window to catch mouse events, I would like to use OnMessage, because of performance, the timer performs well, but it seems not to be the best way to catch the mousemovements and clicks. Anybody knows, where I can find it in the Forum? I searched for it the last days, but didnt find it:-(
Back to top
View user's profile Send private message
majkinetor !
Guest





PostPosted: Thu Feb 08, 2007 6:25 pm    Post subject: Reply with quote

You can use OnMessage with trans win. U have example in the help file, how to make win transparent.


Keywords: WinSet, WM_MOUSEXXX messages, OnMessage
Back to top
garath



Joined: 24 Mar 2005
Posts: 372
Location: germany

PostPosted: Thu Feb 08, 2007 9:40 pm    Post subject: Reply with quote

@majkinetor !
I tried to get WM_Mouse messages, but I only got them with non-transparent AHK-Windows, will do some further research the next days.
I tried it with the OnScreenDisplay example, but only got Messages hovering over the visible text, not over the transparent window Sad If I remove transparecy, I get the messages :-/
Back to top
View user's profile Send private message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Fri Feb 09, 2007 3:08 am    Post subject: Reply with quote

garath wrote:
Btw, long time ago I saw somebody using a transparent window to catch mouse events


I tried it, maybe you mean this thread?

http://www.autohotkey.com/forum/viewtopic.php?t=10126

I never did get it to work in AHK very well.
_________________
____________________
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Fri Feb 16, 2007 12:10 pm    Post subject: Reply with quote

When I had this problem, I created a .dll with MASM32 to solve it. The license agreement on that is pretty restrictive... so I just kept it for personal use.

I don't know if you are still working on this, but I finally transfered the code over into RosAsm, which is under the GPL license. Since I can now do with it what I want, so can you Very Happy

The DLL installs a low-level mouse hook and uses PostMessage to notify the script that a mouse event has occured. It doesn't care what mouse event... any will do. The script has to do all the work. Also, it doesn't pass any parameters to the script. So it is best to just set up hotkeys for the buttons and use the DLL to notify of X/Y movement (which is the only thing it was created for).

The DLL is written in Assembly Language and for what it does it is pretty much optimized.

Code in the DLL:
Code:
[hInstance: ?    hHook : ?    hWnd : ?]

Proc Main:
    Arguments @Instance, @Reason, @Reserved

        If D@Reason = &DLL_PROCESS_ATTACH
           push D@Instance
           pop D$hInstance
        Else_If D@Reason = &DLL_PROCESS_DETACH
            ; ...

        Else_If D@Reason = &DLL_THREAD_ATTACH
            ; ...

        Else_If D@Reason = &DLL_THREAD_DETACH
            ; ...

        End_If

        mov eax &TRUE
Endp




Proc MouseProc::
    Arguments @nCode, @wParam, @lParam

    push D@lParam
    push d@wParam
    push d@nCode
    push D$hHook
    call 'user32.CallNextHookEx'

    push 3000h
    push D$hWnd
    call 'user32.PostMessageA'

    xor eax eax

EndP

Proc HookMouse::
    Arguments @hWnd

    push D@hWnd
    pop D$hWnd

    push &NULL
    push D$hInstance
    push MouseProc
    push &WH_MOUSE_LL
    call 'user32.SetWindowsHookExA'
    push eax
    pop D$hHook

EndP

Proc UnhookMouse::

    push D$hHook
    call 'user32.UnhookWindowsHookEx'

    xor eax eax

EndP


Sample script:
Code:
OnExit, Exit

PID := DllCall("GetCurrentProcessId")
  If ErrorLevel
    MsgBox %ErrorLevel%

DllCall("Hook.dll\HookMouse", "UInt", PID)
  If ErrorLevel
    MsgBox %ErrorLevel%

OnMessage(0x3000,"DoMouse")

Return



DoMouse()
{
  MouseGetPos, x, y
  TrayTip,, %x% : %y%
  Return
}


Esc::ExitApp

Exit:
DllCall("Hook.dll\UnhookMouse")
ExitApp
Return


DLL is here: Hook.DLL

You can download RosAsm to see the code inside Smile

A note...

You don't have to use GetCurrentProcessId for the PostMessage handle. You can use GetCurrentThread, GetCurrentThreadId, or if your script has some kind of GUI, use the Window hWnd for it...etc etc.

Hope you (or at least someone) finds it useful Smile
Back to top
garath



Joined: 24 Mar 2005
Posts: 372
Location: germany

PostPosted: Fri Feb 16, 2007 5:36 pm    Post subject: Reply with quote

I am working on it, from time to time.
Thanks for the hook, will have a look on it, this weekend. Smile
Right now, I have implemented a gui, scalable replay-speed from 10%-2500%, and a Keyboard-recorder, I only have to secure, that no skript-kiddie can use it as K_e_y-L_o_G_g_e_r Sad
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Feb 21, 2007 12:07 am    Post subject: Reply with quote

Doesn´t work for me at all....
Back to top
Antti
Guest





PostPosted: Sat Mar 31, 2007 10:52 am    Post subject: Reply with quote

Mouse movement recorder works well with me ( XP SP1 ).

It is awesome.

Just what I do need.


Thank you very match for sharing !!!
---

What I do want to point out to new people who did not get it work is that.

When you copy it to clipboard and paste it to notepad there was this line warped in two lines.

If (xpos<>xpos_old OR ypos<>ypos_old OR Wheel_up OR Wheel_down OR lButt<>Lbutt_old OR mButt<>mButt_old OR rButt<>rButt_old)


It need to be in one line like that.

So remove some spaces and save.

Hopefully that will help someone.
Back to top
majkinetor



Joined: 24 May 2006
Posts: 3622
Location: Belgrade

PostPosted: Sat Mar 31, 2007 11:14 am    Post subject: Reply with quote

Quote:
I tried it with the OnScreenDisplay example, but only got Messages hovering over the visible text, not over the transparent window If I remove transparecy, I get the messages :-/

Its true.
You can monitor screen mouse movement. When mouse is inside rectangle of your window, you do your job.

Zippo() wrote:
Hope you (or at least someone) finds it useful

Very nice. thx
_________________
Back to top
View user's profile Send private message MSN Messenger
quatermass



Joined: 14 Dec 2005
Posts: 107

PostPosted: Wed Apr 04, 2007 10:20 am    Post subject: Reply with quote

Any chance that it could be modified to repeat the same mouse movement a set number of times?

I tried
Code:

f3::
loop, 5
{
Gosub, replay
}
Return


but it doesn't make it repeat.
_________________
Stuart Halliday
Back to top
View user's profile Send private message
Bezzie
Guest





PostPosted: Fri Feb 01, 2008 5:18 pm    Post subject: Reply with quote

Bump?
Back to top
Cassak
Guest





PostPosted: Thu Feb 07, 2008 2:53 pm    Post subject: Reply with quote

loop, 2
{
Send {F3}
Sleep, 1883000
}

Create a second script that looks like this. Set the time for however long your recording takes to replay. Set the loop for however many times you want it to replay.

Open the MoRe script, then open the second script when you want to start. Your second script wil start the MoRe script and repeat it for howver many time you specifiy.

I also added a pause funtion to the original script because I found I could not stop it once it started replaying and I had to unplug my computer :S

f2::
SetTimer, WatchMouse, Off
ToolTip
Return

f3::Gosub, replay
F4::Pause
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group