Skip to content

Instantly share code, notes, and snippets.

@brentvollebregt
Created April 11, 2017 02:49
Show Gist options
  • Save brentvollebregt/6e53b013d36ff7be3cf146948c763a51 to your computer and use it in GitHub Desktop.
Save brentvollebregt/6e53b013d36ff7be3cf146948c763a51 to your computer and use it in GitHub Desktop.
A Python 3 mouselogger using the pynput module
# From: https://github.com/moses-palmer/pynput
from pynput.mouse import Listener
import logging
log_dir = ""
logging.basicConfig(filename=(log_dir + "mouse_log.txt"), level=logging.DEBUG, format='["%(asctime)s", %(message)s]')
def on_click(x, y, button, pressed):
if pressed:
logging.info('"{0}", {1}'.format(button, (x, y)))
def on_scroll(x, y, dx, dy):
logging.info('"{0}", {1}'.format('Button.scroll', (x, y)))
with Listener(on_click=on_click, on_scroll=on_scroll) as listener:
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment