Faulty keyboard program in python