from pynput.mouse import Listener, Button
class ClickListener:
def __init__(self):
self.ClickTimes = 0
self.CurrentClick = 0
self.ClickPositions = []
def on_click(x, y, button, pressed):
if pressed and button == Button.middle:
ClickPositions.append((x,y))
self.CurrentClick += 1
if self.ClickTimes <= self.CurrentClick:
return Falses
def getClicks(self, nr):
self.ClickPositions = []
self.CurrentClick = 0
self.ClickTimes = nr
with Listener(on_click = ClickListener.on_click) as listener:
listener.join()
return self.ClickPositions
在函数'on_click'上,由于调用该函数的事件是如何获得自我属性的?看来我无法将自我对象传递给事件。
Edit1。:
class ClickListener:
def __init__(self):
self.ClickTimes = 0
self.CurrentClick = 0
self.ClickPositions = []
def on_click(self, x, y, button, pressed):
if pressed and button == Button.middle:
self.ClickPositions.append((x,y))
self.CurrentClick += 1
if self.ClickTimes <= self.CurrentClick:
return Falses
def getClicks(self, nr):
self.ClickPositions = []
self.CurrentClick = 0
self.ClickTimes = nr
with Listener(on_click = self.on_click) as listener:
listener.join()
return self.ClickPositions
在这种情况下,它说缺少一个必需的参数,即“按下”的参数。
答案 0 :(得分:0)
您可以使用类似这样的东西。
/etc/exports