[英]How to detect mouse click in python 3 on linux?
I am very new to python, and I want to be able to detect mouse click events across the entire screen. 我是python的新手,我希望能够在整个屏幕上检测鼠标点击事件。
This question is closest to what I want, however none of the answers are very descriptive. 这个问题与我想要的最接近,但是没有一个答案是非常具有描述性的。
How can I do this? 我怎样才能做到这一点?
you can handle mouse input using the lib PyUserInput (code sample from github) : 你可以使用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()
otherwise, you can do it with the Xlib
lib : Python Xlib catch/send mouseclick 否则,您可以使用
Xlib
lib执行此操作: Python Xlib catch / send mouseclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.