SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

How to stop a PyMouseEvent #111

Closed imnotkk closed 6 years ago

imnotkk commented 6 years ago

I am trying to build a program whose first part is saving user clicks for calibration purposes.

I am using PyUserInput for this (on Python 3.5.2) and following your tutorial on GitHub. Currently, this is my code:

from pymouse import PyMouseEvent

positions = []

class Click(PyMouseEvent):
    def __init__(self):
        PyMouseEvent.__init__(self)

    def click(self, x, y, button, press):
        if button == 1:
            if press:
                print('Click! X=%d - Y=%d' % (x, y))
                positions.append((x, y))
                print(positions)
        if len(positions) >= 4:
            self.stop()

C = Click()
C.run()

print('Calibrated')

The problem I'm running into is that, even after the PyMouseEvent stops (when position reaches 4 values), I cannot run anything after it (i.e. 'Calibrated' does not print).

How can I continue to run scripts after calling stop() on PyMouseEvent?

I appreciate any help.

pepijndevos commented 6 years ago

You're supposed to call C.start() which runs the event thread.

Also, this repo is abandoned, have a look here: https://github.com/PyUserInput/PyUserInput