diff --git a/mouselogger/README.md b/mouselogger/README.md new file mode 100644 index 0000000..01ebfed --- /dev/null +++ b/mouselogger/README.md @@ -0,0 +1,13 @@ + +# mouselogger.py + +Script that timestamps and logs all mouse input to file. + +## requirements +works on python3.9 +pynput module `pip install pynput` + +## usage +from the commandline: ++ `python mouselogger.py` will log all mouse input to default logfile `mouselog.log` in the same folder ++ `python mouselogger.py [user-specified logfile]` will instead log to user-specified logfile \ No newline at end of file diff --git a/mouselogger/mouselogger.py b/mouselogger/mouselogger.py new file mode 100644 index 0000000..fe68b7d --- /dev/null +++ b/mouselogger/mouselogger.py @@ -0,0 +1,55 @@ +import sys +import time +from pynput import mouse + +# default logfile +logfile="mouselog.log" + +try: + sys.argv[1] +except IndexError: + print("no logfile given, appending to %s" % logfile) +else: + logfile=sys.argv[1] + print("logfile set to %s" % logfile) + +f = open(logfile, "a") +print("now logging all mouse input..") + +def on_move(x, y): + f.write('{0:.7f} Pointer moved to {1}\n'.format( + time.time(), (x, y))) + +def on_click(x, y, button, pressed): + f.write('{0:.7f} {1} {2} at {3}\n'.format( + time.time(), + 'Pressed' if pressed else 'Released', + button, + (x, y))) + #if not pressed: + # Stop listener + # return False + +def on_scroll(x, y, dx, dy): + f.write('{0:.7f} Scrolled {1} at {2}\n'.format( + time.time(), + 'down' if dy < 0 else 'up', + (x, y))) + +# # Collect events until released +# with mouse.Listener( +# on_move=on_move, +# on_click=on_click, +# on_scroll=on_scroll) as listener: +# listener.join() + +# ...or, in a non-blocking fashion: +listener = mouse.Listener( + on_move=on_move, + on_click=on_click, + on_scroll=on_scroll) +listener.start() + + +input("press ENTER to stop logging") +print("ok thanks, logged all mouse input to %s" % logfile) \ No newline at end of file