Be sure to initialize all fields of synthetic SDL_MouseButtonEvent.
Don't access "ev.button.which" for SDL_MOUSEMOTION as it is not a button event.