5

I am very new to python, and I want to be able to detect mouse click events across the entire screen.

This question is closest to what I want, however none of the answers are very descriptive.

How can I do this?

Community
  • 1
  • 1
gandalf3
  • 1,636
  • 4
  • 24
  • 40
  • 7
    I would probably vote this up no matter what you had asked just because you appear to be Gandalf asking a Linux question, but I also happen to find the question pertinent. – temporary_user_name Dec 17 '13 at 08:29
  • Maybe this can help: [LINK][1] But this needs sudo rights. [1]: http://stackoverflow.com/questions/4855823/get-mouse-deltas-using-python-in-linux – Simon Sagi Dec 17 '13 at 09:10

1 Answers1

8

you can handle mouse input using the lib PyUserInput (code sample from 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

Community
  • 1
  • 1
onionpsy
  • 1,502
  • 11
  • 15