按下鼠标即可打印

按下鼠标即可打印,第1张

按下鼠标即可打印

我认为,正如Oli在他的评论中指出的那样,当按住鼠标按钮时,点击的源源不断,因此您必须

print
循环使用。使
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()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5631123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存