📅  最后修改于: 2023-12-03 15:04:36.042000             🧑  作者: Mango
在Python中,有多种库可以用于键盘记录,其中最常用的包括pyhook、pynput和keyboard。本文将着重讨论这三个库。
pip install pyHook
import pythoncom, pyHook
def onKeyboardEvent(event):
print('Key: ', event.Key)
return True
hm = pyHook.HookManager()
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
pip install pynput
from pynput import keyboard
def on_press(key):
print('Key: ', key)
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
pip install keyboard
import keyboard
def on_press(event):
print('Key: ', event.name)
keyboard.on_press(on_press)
keyboard.wait()
以上是三种常用的Python键盘记录器。每个库的功能和用法略有不同,根据实际需求选择使用就好了。