我认为,正如Oli在他的评论中指出的那样,当按住鼠标按钮时,点击的源源不断,因此您必须
while循环在同一线程上运行可以防止在释放鼠标时触发click事件,因此,我想到的唯一方法就是
print("click")从单独的线程中实现。
我不是Python程序员,但是我有一个在我的机器上可以使用的刺刀(Windows 8.1上的Python 2.7):
from pymouse import PyMouseEventfrom threading import Threadclass DetectMouseClick(PyMouseEvent): def __init__(self): PyMouseEvent.__init__(self) def print_message(self): while self.do == 1: print("click") def click(self, x, y, button, press): if button == 1: if press: print("click") self.do = 1 self.thread = Thread(target = self.print_message) self.thread.start() else: self.do = 0 print("end") else: self.do = 0 self.stop()O = DetectMouseClick()O.run()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)