xxxxxxxxxx
from pynput.mouse import Listener
import logging
logging.basicConfig(filename="mouse_log.txt", level=logging.DEBUG, format='%(asctime)s: %(message)s')
def on_move(x, y):
logging.info("Mouse moved to ({0}, {1})".format(x, y))
def on_click(x, y, button, pressed):
if pressed:
logging.info('Mouse clicked at ({0}, {1}) with {2}'.format(x, y, button))
def on_scroll(x, y, dx, dy):
logging.info('Mouse scrolled at ({0}, {1})({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()
xxxxxxxxxx
import ctypes
import time
# see http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx for details
MOUSE_LEFTDOWN = 0x0002 # left button down
MOUSE_LEFTUP = 0x0004 # left button up
MOUSE_RIGHTDOWN = 0x0008 # right button down
MOUSE_RIGHTUP = 0x0010 # right button up
MOUSE_MIDDLEDOWN = 0x0020 # middle button down
MOUSE_MIDDLEUP = 0x0040 # middle button up
def pos(x, y):
ctypes.windll.user32.SetCursorPos(x, y) # set mouse position
def left_click():
ctypes.windll.user32.mouse_event(MOUSE_LEFTDOWN) # left down
ctypes.windll.user32.mouse_event(MOUSE_LEFTUP) # left up
def right_click():
ctypes.windll.user32.mouse_event(MOUSE_RIGHTDOWN) # right down
ctypes.windll.user32.mouse_event(MOUSE_RIGHTUP) # right up