Fix a horrible bug in the X11 event handler.

This issue was the cause of some bad keyboard bugs that I thought was actually
X11's fault, which of course wasn't. Comments have been fixed.