Fixed keyinput.py to properly cleanup when it crashes