为什么用 pynput 无法检测到特定按键?
我正在尝试制作一个在后台运行并检测按下某个键以创建一种热键的程序,但由于某种原因我无法检测到一个特定的键。
from pynput.keyboard import Key, Listener
def on_press(key):
print(key)
if str(key) == str('4'):
print("test")
with Listener(on_press=on_press) as listener:
listener.join()
预期产出:
'4'
test
实际产出:
'4'
I'm trying to make a program which runs in the background and detects a certain key being pressed to create a kind of hotkey, but for some reason I can't detect one specific key.
from pynput.keyboard import Key, Listener
def on_press(key):
print(key)
if str(key) == str('4'):
print("test")
with Listener(on_press=on_press) as listener:
listener.join()
Expected Output:
'4'
test
Actual Output:
'4'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下内容应该有所帮助:
输出如下:
'f'
'g'
'j'
'd'
'你'
'j'
'k'
'e'
'd'
'r'
't'
'j'
‘6’
‘6’
‘4’
测试
‘4’
测试
‘4’
测试
‘4’
测试
‘4’
测试
我使用了以下指南:
https://buildmedia.readthedocs。 org/media/pdf/pynput/latest/pynput.pdf
the following should help:
the output is following:
'f'
'g'
'j'
'd'
'y'
'j'
'k'
'e'
'd'
'r'
't'
'j'
'6'
'6'
'4'
test
'4'
test
'4'
test
'4'
test
'4'
test
I have used the following guide:
https://buildmedia.readthedocs.org/media/pdf/pynput/latest/pynput.pdf