From 41dc50bf16e9e2b004e48e99c76b01ff4341b17d Mon Sep 17 00:00:00 2001 From: merijn Date: Tue, 23 Mar 2021 10:36:11 +0100 Subject: [PATCH] mouselogger.py script for logging all mouse input to logfile --- mouselogger/README.md | 13 +++++++++ mouselogger/mouselogger.py | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 mouselogger/README.md create mode 100644 mouselogger/mouselogger.py 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