Optimize getMousePosition.