Greatly improved event handling for both keyboard and mouse