Quick answer: Pygame Key.get_mods() returning Shift-held after Alt-Tab? OS sends no keyup on focus loss - listen for WINDOWFOCUSLOST; clear modifier state.

Player holds Shift to run; Alt-Tabs; returns; character keeps running.

Clear on focus lost

if event.type == pygame.WINDOWFOCUSLOST:
    pygame.key.set_mods(0)

Resets modifier state. Subsequent reads accurate.

Or re-query on focus

OS-level state via platform API. More involved; works.

Track press/release per modifier

Per-modifier state machine. Resilient to focus loss.

“Focus loss is an unreliable event boundary. State needs explicit cleanup.”

If your game has modifier-driven actions, the focus handling is mandatory.

Related reading