Fixed a bug in keyboard event handling.