Reputation: 31
I try to get this example code for pynput working:
from pynput import keyboard
def on_activate_h():
print('<ctrl>+<alt>+h pressed')
def on_activate_i():
print('<ctrl>+<alt>+i pressed')
with keyboard.GlobalHotKeys({
'<ctrl>+<alt>+h': on_activate_h,
'<ctrl>+<alt>+i': on_activate_i}) as h:
h.join()
But after I put in the hotkey I get back the following error:
Unhandled exception in listener callback
Traceback (most recent call last):
File "/Users/name/workspace/julian/python-projects/python-keyboard/my-venv/lib/python3.13/site-packages/pynput/_util/__init__.py", line 229, in inner
return f(self, *args, **kwargs)
File "/Users/name/workspace/julian/python-projects/python-keyboard/my-venv/lib/python3.13/site-packages/pynput/_util/darwin.py", line 283, in _handler
self._handle(proxy, event_type, event, refcon)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '_thread._ThreadHandle' object is not callable
It worked before put suddenly stopped. Tried to reinstall python already but nothing works.
Upvotes: 3
Views: 454
Reputation: 3040
Python 3.13 is currently unsupported for pynput
unfortunately. You can add a comment on the issue above, that you have the same problem, but until then, try an older Python version.
Update (November 12th 2024):
Linked issue above was moved to this.
Owner writes:
I cannot reproduce this error, but the stack trace seems to indicate that the problem may be internal changes to the Python threading library in Python 3.13 on Windows; self._handle is a method of the listener class, but it seems to have been overwritten by the threading library once the thread is started.
In retrospect, letting the listener classes be subclasses of threading.Thread was a poor choice, but one that probably cannot be undone until the next major version of this library. In the mean time, I have prepared a branch with a possible fix:
fixup/win32-mouse-listener
.
Upvotes: 1