1. 安装pyhook 和 PyUserInput pyhook直接安装会报错,需要到下面网址下载后再安装: https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载 pyhook对应版本 pip install ***.whl pip install PyUserInput 2. 监控鼠标
from pymouse import PyMouseEvent
class Mouse(PyMouseEvent):
def __init__(self):
PyMouseEvent.__init__(self)
def click(self, x, y, button, press):
if button == 1:
if press:
print(x, y)
else:
return
def move(self, x, y):
print(x, y)
m = Mouse()
m.run()
3.监控键盘
from pykeyboard import PyKeyboardEvent
class Keyb(PyKeyboardEvent):
def __init__(self):
PyKeyboardEvent.__init__(self)
self.input = ""
def tap(self, keycode, character, press):
print(keycode,character,press)
if press:
self.input+=character
print(self.input)
k = Keyb()
k.run()