加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何在linux上的python 3中检测鼠标点击?

发布时间:2020-12-14 00:53:32 所属栏目:Linux 来源:网络整理
导读:我是 python的新手,我希望能够在整个屏幕上检测鼠标点击事件. This question最接近我想要的,但没有一个答案是非常具有描述性的. 我怎样才能做到这一点? 解决方法 您可以使用lib PyUserInput处理鼠标输入(来自github的代码示例): from pymouse import PyMou
我是 python的新手,我希望能够在整个屏幕上检测鼠标点击事件.

This question最接近我想要的,但没有一个答案是非常具有描述性的.

我怎样才能做到这一点?

解决方法

您可以使用lib PyUserInput处理鼠标输入(来自github的代码示例):

from pymouse import PyMouseEvent

def fibo():
    a = 0
    yield a
    b = 1
    yield b
    while True:
        a,b = b,a+b
        yield b

class Clickonacci(PyMouseEvent):
    def __init__(self):
        PyMouseEvent.__init__(self)
        self.fibo = fibo()

    def click(self,x,y,button,press):
        '''Print Fibonacci numbers when the left click is pressed.'''
        if button == 1:
            if press:
                print(self.fibo.next())
        else:  # Exit if any other mouse button used
            self.stop()

C = Clickonacci()
C.run()

否则,你可以使用Xlib lib:Python Xlib catch/send mouseclick

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读