Fixed error in the key events. Used a timer instead.