Keyboard handling fixes