Implemented X11 KeyDown/KeyUp events and reduced code duplication