我正在尝试制作类似键盘记录器的东西,我目前正在使用 pynput 库,但问题是程序总是执行我导入的最后一件事,例如,如果我首先导入鼠标侦听器,它不会捕获键盘或其他有没有办法可以同时使用两个库?
from pynput.keyboard import Key, Listener
from pynput.mouse import Listener
def on_press(key):
print('{0} pressed'.format(
key))
def on_release(key):
print('{0} release'.format(
key))
def on_move(x, y):
print('Pointer moved to {0}'.format(
(x, y)))
def on_click(x, y, button, pressed):
print('{0} at {1}'.format(
'Pressed' if pressed else 'Released',
(x, y)))
def on_scroll(x, y, dx, dy):
print('Scrolled {0}'.format(
(x, y))),
# Collect events until released
with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll, on_press=on_press, on_release=on_release) as listener:
listener.join()
红糖糍粑
墨色风雨
胡子哥哥
相关分类