python键盘记录
时间: 2023-11-09 10:03:41 浏览: 235
python你TM太皮了——区区30行代码就能记录键盘的一举一动.pdf
如果你想在 Python 中记录键盘输入,可以使用第三方库 pynput。以下是一个简单的示例代码,可以记录用户按下和释放的键以及按下的时间:
```python
from pynput import keyboard
def on_press(key):
try:
print('Key {} pressed at {}'.format(key.char, key.time))
except AttributeError:
print('Special key {} pressed at {}'.format(key, key.time))
def on_release(key):
print('Key {} released at {}'.format(key, key.time))
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
```
阅读全文