[Python]pynputでマウスのクリックイベントを取得して処理する | pixelbeat sandbox

from pynput import mouseclass Monitor: def __init__(self): self.counter = 0 self.over_count = 5 def count(self): self.counter += 1 print(‘Count:{0}’.format(self.counter)) def is_over(self): return True if self.counter >= self.over_count else False def call(self): self.count() if self.is_over(): print(‘Done’) self.listener.stop() # 規定回数過ぎたら終了 def on_click(self, x, y, button, pressed): print(‘{0} at {1}’.format( ‘Pressed’ if pressed else ‘Released’, (x,y))) if pressed: self.call() def start(self): with mouse.Listener( on_click=self.on_click) as self.listener: self.listener.join()monitor = Monitor()monitor.start()

情報源: [Python]pynputでマウスのクリックイベントを取得して処理する | pixelbeat sandbox