title: Mouse position recorder
body: <p>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, <strong>only when the user clicks the mouse</strong>. The format is csv:</p>
  
  <pre><code>timestamp, mouse_btn_name mouse_xpos,mouse_ypos, title_window_handler
  </code></pre>
  
  <p>I found an <a href="http://www.autohotkey.com/docs/commands/MouseGetPos.htm" rel="nofollow">example here</a>, but now a complete one as per my requirements. How do I do the logging?</p>
  
  <pre><code>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
  </code></pre>