Updated keyboard input handler