我正在编写一个代码,可以使用PyHook3从按键事件中获取按键。
仅当用户在同一控件(例如,文本框)上键入时,才应构建字符串。这是我尝试过的代码
def OnKeyboardEvent(pipe, queue, event):
if "Oem" in event.Key:
write_log ('MessageName:' + event.MessageName
+ 'Time:' + datetime.datetime.utcfromtimestamp((bootTime + event.Time)/1000).strftime('%c')
+ 'Window:' + str(event.Window)
+ 'Key:' + chr(event.Ascii))
else:
write_log('MessageName:' + event.MessageName
+ 'Time:' + datetime.datetime.utcfromtimestamp((bootTime + event.Time) / 1000).strftime('%c')
+ 'Window:' + str(event.Window)
+ 'Key:' + event.Key)
return True
这是日志的样子
MessageName:key downTime:Tue Nov 13 11:12:24 2018Window:788290Key:T MessageName:key downTime:Tue Nov 13 11:12:24 2018Window:788290Key:E MessageName:key downTime:Tue Nov 13 11:12:25 2018Window:788290Key:S MessageName:key downTime:Tue Nov 13 11:12:25 2018Window:788290Key:T MessageName:key downTime:Tue Nov 13 11:12:30 2018Window:788290Key:Return
如果您可以在日志中看到这些关键事件,则这些事件在ID为 788290 的窗口中发生。如果它是相同的窗口ID,则必须将其记录为字符串。你们可以帮我吗?