Fixed bug with key press handling