本文介绍了在Python中使用Pynput检查特定的密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dpressed = 0
def on_press(key):
if key == ('d'):
global dpressed
dpressed+=1
logging.info("D: %s" % dpressed)
当我运行此代码并按d时,什么都没发生,我怀疑是因为在检查时需要将该键称为其他名称.有人知道应该是什么吗?
When I run this code and press d, nothing happens, which I suspect is because the key needs to be called something else when checked. Does someone know what it should be?
推荐答案
对于其他可能遇到此问题的人,我从顶部的pynput.keybord导入了KeyCode.然后我将('d')更改为KeyCode.from_char('d').这应该对任何有此问题的人都有效. 此处
For anyone else that may have this problem, I imported KeyCode from pynput.keybord at the top. Then I changed ('d') to KeyCode.from_char('d'). This should work for anyone with this problem. There is a great explanation here
这篇关于在Python中使用Pynput检查特定的密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!