Keyboard input handling, version 2.

I hope it bettere mulates XQuartz/quartz-wm behavior now.