Refactored mouse event generation.