defon_release(key): if key == keyboard.Key.esc: returnFalse
with keyboard.Listener(on_press=on_press, on_release=on_release) as lsn: lsn.join()
监控鼠标
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from pynput import mouse
defon_click(x, y, button, pressed): if button == mouse.Button.left: print('left was pressed!') elif button == mouse.Button.right: print('right was pressed!') returnFalse else: print('mid was pressed!')
# 定义鼠标监听线程 with mouse.Listener(on_click=on_click) as listener: listener.join()
from pynput import keyboard, mouse from loguru import logger from threading import Thread
# 定义日志文件 logger.add('moyu.log')
defon_press(key): logger.debug(f'{key} :pushed')
defon_release(key): if key == keyboard.Key.esc: returnFalse
# 定义键盘监听线程 defpress_thread(): with keyboard.Listener(on_press=on_press, on_release=on_release) as lsn: lsn.join()
defon_click(x, y, button, pressed): if button == mouse.Button.left: logger.debug('left was pressed!') elif button == mouse.Button.right: logger.debug('right was pressed!') else: returnFalse
# 定义鼠标监听线程 defclick_thread(): with mouse.Listener(on_click=on_click) as listener: listener.join()