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

Keyboard capture in X11 causes an error (Python 3) #60

Closed jnv closed 8 years ago

jnv commented 9 years ago

After subclassing PyKeyboardEvent and setting self.capture = True I get this error:

Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/home/pi/.local/lib/python3.2/site-packages/pykeyboard/x11.py", line 286, in run
    self.display2.screen().root.grab_keyboard(True, X.KeyPressMask | X.KeyReleaseMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
TypeError: grab_keyboard() takes exactly 5 positional arguments (8 given)

This is obvious by looking into python3-xlib source. Maybe the API changed from python-xlib?

The following fix works for me: https://github.com/jnv/PyUserInput/commit/81da6dfb9c056f40623c085dda86c6aae80857d9 though I'm not quite sure I got the arguments right. It captures the keyboard and releases it with a workaround suggested in #48.

LiuLang commented 9 years ago

@SavinaRoja I've checked grab_keyboard() method in python-xlib and python3-xlib, they both only accept 5 parameters: def grab_keyboard(self, owner_events, pointer_mode, keyboard_mode, time)

To fix this problem, just remove useless arguments in pykeyboard/x11.py: self.display2.screen().root.grab_keyboard(X.KeyPressMask | X.KeyReleaseMask, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)

pepijndevos commented 8 years ago

I think this is fixed? Could anyone confirm?