I have a logger that listens to sequences such as equations, but I need to remove all the keypresses like “L_control” or “shift”, what I do is get the ascii number and then use chr(event.Ascii) but it comes back with the ctrl and shift presses as a space.
I’m currently using this to remove all the characters I don’t want but it doesn’t seem to work. Any ideas of improvements?
def removeChars(l):
acceptedChars = ["[", "]", "+", "-", "/", "*", "^", "*", "(", ")"]
newL = ""
for x in range(0, len(l)):
if l[x].isalpha() or l[x] in acceptedChars or l[x].isdigit():
newL = newL + l[x]
return newL
Edit:
I am using pyHook to get the key event and using event.Ascii to get the Ascii value then using chr(event.Ascii) to get the character
What about something like this?
Edit:
You can use anything in
set()to match to for example to just get digits, letters, and selected symbols: