A simple module that would enqueue user events in a different queue then the regular events, meaning they would only be captured by the loop requesting this specific events.
It's important that even if the main sdl loop is faster then the auxiliary loop (that runs in a different thread), the queued events should not be captured by a different loop than the loop expecting for them.
The API could be something like (inspired by Thread::Queue):
# adds a new event in the queue
# fetches the next event from the queue in blocking mode
# fetches the next event from the queue in non-blocking mode
# are there any pending events in this queue?
The queue could be an object, but making it a regular unblessed string makes it easier for sharing between threads.
The $event information should be serialized with Storable::freeze in order to avoid becoming undef as it is migrated to a different thread.