解决pynput库在Python 3.13中鼠标监听回调报错问题?

想使用pynput监听鼠标或者键盘的功能,python使3.13 ,pynput 1.7.7,示例直接copy的官网示例,但是一直报错
代码如下:
from pynput import mouse

def on_move(x, y):

print('Pointer moved to {0}'.format(
    (x, y)))

def on_click(x, y, button, pressed):

print('{0} at {1}'.format(
    'Pressed' if pressed else 'Released',
    (x, y)))
if not pressed:
    # Stop listener
    return False

def on_scroll(x, y, dx, dy):

print('Scrolled {0} at {1}'.format(
    'down' if dy < 0 else 'up',
    (x, y)))

Collect events until released

with mouse.Listener(

    on_move=on_move,
    on_click=on_click,
    on_scroll=on_scroll) as listener:
listener.join()

报错日志如下:
Unhandled exception in listener callback
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pynput\_util\win32.py", line 386, in _handler

converted = self._convert(code, msg, lpdata)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pynput\_util\win32.py", line 401, in _convert

raise NotImplementedError()

NotImplementedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pynput\_util\__init__.py", line 229, in inner

return f(self, *args, **kwargs)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pynput\_util\win32.py", line 390, in _handler

self._handle(code, msg, lpdata)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^

TypeError: '_thread._ThreadHandle' object is not callable

pynput进行其他的比如按键,移动模拟没有问题,但是只要添加回调监听运行就会报错
尝试了下将python版本退回3.6,发现就正常了,那是不是只能回退版本玩了?

阅读 1.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏