提问人:gyu29 提问时间:11/17/2023 最后编辑:Cowgyu29 更新时间:11/17/2023 访问量:16
ValueError:“键'u'未映射到任何已知键。在 mac 上使用键盘模块时,我会遇到这种情况
ValueError: "Key 'u' is not mapped to any known key. This happens to me while using keyboard module on mac
问:
所以我正在制作一个 python 脚本,当按下某个键时它会切换录制/播放,所以为了监听这些键,我使用键盘模块来监听它,但是当我运行我的脚本时,它不起作用。法典
Exception in thread Thread-1 (listen):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
Traceback (most recent call last):
File "/Users/*****/Desktop/test.py", line 36, in <module>
if keyboard.is_pressed('u'):
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 417, in is_pressed
steps = parse_hotkey(hotkey)
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 344, in parse_hotkey
scan_codes = key_to_scan_codes(hotkey)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/__init__.py", line 324, in key_to_scan_codes
raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e)
self.run()
ValueError: ("Key 'u' is not mapped to any known key.", ValueError('Unrecognized character: u'))
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
我期望我的脚本在我按下“u”或“p”键时触发事件。然而,相反,我得到了一长串错误。
答: 暂无答案
评论