1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from pynput.mouse import Listener class Watcher: def on_move(self, x, y): # 监听鼠标移动 print('鼠标滑/移动{0}'.format((x, y))) def on_click(self, x, y, button, pressed): # 监听鼠标点击 if pressed: print('鼠标按下{0}'.format((x, y))) else: # Released, 鼠标松开 print('鼠标松开{0}'.format((x, y))) def on_scroll(self, x, y, dx, dy): # 监听鼠标滚轮 print('滑轮滚动{0}'.format((x, y))) def watch(self): with Listener(on_move=self.on_move, on_click=self.on_click, on_scroll=self.on_scroll) as listener: try: listener.join() except Exception as e: print('{0} was clicked'.format(e.args[0])) # 连接事件以及释放 # 一个鼠标监听器是一个线程。线程,所有的回调将从线程调用。 # 从任何地方调用pynput.mouse.Listener.stop, # 或者调用pynput.mouse.Listener.StopException # 或从回调中返回False来停止监听器。 Watcher().watch() |
- end
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/3159.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设