Advertisement
mateon1

Mouse logger

May 9th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import win32api,time
  2.  
  3. LOGFILE="mouseLog.txt"
  4. slp=0.5
  5. mouseLeft=1
  6. mouseRight=2
  7. mouseMiddle=4
  8. counter=0
  9. autosv=10
  10. try:
  11.     with open(LOGFILE) as f:
  12.         log=f.read()
  13. except:
  14.     print "Log file not found, making one..."
  15.     with open(LOGFILE,"w") as f:
  16.         f.write("")
  17.     log=""
  18.  
  19. try:
  20.     while True:
  21.         MLV = win32api.GetKeyState(mouseLeft)
  22.         MRV = win32api.GetKeyState(mouseRight)
  23.         MMV = win32api.GetKeyState(mouseMiddle)
  24.         print "%s %s %s              \r"%(MLV,MMV,MRV),
  25.         time.sleep(slp)
  26.         counter+=1
  27.         log+="%s: %s\t%s\t%s\n"%(time.ctime(time.time()),MLV,MMV,MRV)
  28.         if not counter%autosv:
  29.             with open(LOGFILE,"w") as f:
  30.                 f.write(log)
  31. except KeyboardInterrupt:
  32.     with open(LOGFILE,"w") as f:
  33.         f.write(log+"***%s: Interrupted\n"%(time.ctime(time.time())))
  34.     raise KeyboardInterrupt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement