Improve keyboard handling