Improve hardware keyboard handling