Reorganized definition and handling of input events.