iceman
iceman

Reputation: 4261

Mouse position recorder

For a Windows 7 app, I want to write a simple script which can log the current position of the timestamp, the mouse cursor and the window name in a csv log file. I want it to log in the background for usability testing of my program, only when the user clicks the mouse. The format is csv:

timestamp, mouse_btn_name mouse_xpos,mouse_ypos, title_window_handler

I found an example here, but now a complete one as per my requirements. How do I do the logging?

MouseGetPos, xpos, ypos 
Msgbox, The cursor is at X%xpos% Y%ypos%. 

; This example allows you to move the mouse around to see
; the title of the window currently under the cursor:
#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
ToolTip, ahk_id %id%`nahk_class %class%`n%title%`nControl: %control%
return

Upvotes: 1

Views: 933

Answers (1)

Robert Ilbrink
Robert Ilbrink

Reputation: 7963

Your example logs every 100 ms which creates a very long list.
If you only want to log when mouse buttons are clicked, use something like this:

~LButton::
MyButton = Left
GoSub, MyRecord
Return

~RButton::
MyButton = Right
GoSub, MyRecord
Return

MyRecord:
MouseGetPos, xpos, ypos 
WinGetTitle, title, A
FormatTime, CurrentDateTime,, yyyy-MM-dd-HH-mm-ss 
FileAppend, %CurrentDateTime%`,%xpos%`,%ypos%`,%MyButton%`,%title%`n, C:\Temp\Record.csv
Return

Let me know if this suits.
Edits: Changed to csv and separately record left and right mouse actions

Upvotes: 1

Related Questions