Skip to content

Instantly share code, notes, and snippets.

@PureMath86
Created October 9, 2017 06:00
Show Gist options
  • Save PureMath86/6264ab6c855b480b97333f31b8ca4163 to your computer and use it in GitHub Desktop.
Save PureMath86/6264ab6c855b480b97333f31b8ca4163 to your computer and use it in GitHub Desktop.
mouse_logger
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pynput.mouse import Listener
import logging
from importlib import reload
reload(logging)
logging.basicConfig(filename="mouse_log.txt",
level=logging.DEBUG,
format="%(asctime)s: %(message)s")
def on_move(x, y):
# print("Mouse moved to ({0}, {1})".format(x, y))
logging.info("Mouse moved to ({0}, {1})".format(x, y))
def on_click(x, y, button, pressed):
if pressed:
# print("Mouse clicked at ({0}, {1}) with {2}".format(x, y, button))
logging.info("Mouse clicked at ({0}, {1}) with {2}".format(x, y, button))
def on_scroll(x, y, dx, dy):
# print("Mouse scrolled at ({0}, {1}) by ({2}, {3})".format(x, y, dx, dy))
logging.info("Mouse scrolled at ({0}, {1}) by ({2}, {3})".format(x, y, dx, dy))
with Listener(on_move=on_move, 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