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

PyMouseEvent stop method bug #48

Open qoobar opened 10 years ago

qoobar commented 10 years ago

PyMouseEvent stop() method works only when called inside the click() handler. The listener is not stopped when stop() method is called from outside (e.g. by another module). In such situation it still keeps listening for all mouse events - the stop() methods doesn't seem to work. Surprisingly it's not the case with the PyKeyboardEvent - the stop() methods works fine there.

SavinaRoja commented 10 years ago

This is interesting, I will do some testing on it shortly to try to resolve it.

Ilmarinen100 commented 9 years ago

I had the same bug while capturing under linux/x11. I was able to solve it with the following sequence of calls:

c = SomeClassThatExtendsPyMouseEvent()
c.start()
# [....]
from Xlib.display import Display
display = Display()
display.record_disable_context(c.ctx)
display.close()
c.stop()
pepijndevos commented 9 years ago

Maybe related to #55? So probably we're not cleaning up the listener properly. Sadly, documentation is a little sparse.

Ilmarinen100 commented 9 years ago

not quite sure they are related, have you tried XInitThreads yet? a few years ago i needed to call that to prevent random crashes in a multi-threaded opengl program. As for the display thing, why are there two instances of display created in x11.py's PyMouseEvent?

Ilmarinen100 commented 9 years ago
import ctypes
from ctypes.util import find_library
try:
    libpath = find_library("X11")
    from ctypes import *
    x11 = cdll.LoadLibrary(libpath)
    x11.XInitThreads()
    print "XInitThreads() called"
except BaseException, e:
    print "Error occured while trying to call XInitThreads:\n" , e

This is what I used back then, but I guess python-xlib offers something nicer now

pepijndevos commented 9 years ago

Not tried.

There are two displays because... I can't remember, but it did not work with one. I think you can't listen and send to the same display or something.

You seem to know a lot more about it than I do, or did. The Mac code is the only part where I kinda knew what I was doing.

Ilmarinen100 commented 9 years ago

I'll continue to look into it, if I come up with something reliable I'll come back to you... Also, X11 never stops baffling me either, it's a huge mess...