Quick answer: Pygame window losing focus mid-action; player's released key not registered? Windowed deactivation skips keyup events - listen for WINDOWFOCUSLOST and clear input state.

Player holds W to run; alt-tabs; comes back; character keeps running until they press W again.

Clear on focus lost

if e.type == pygame.WINDOWFOCUSLOST:
    held_keys.clear()

Reset input state when window leaves focus. Re-press is fresh.

Re-query OS state on focus

On focus regain, query OS modifier state and re-arm. Holds that persisted physically are recovered.

Use pygame.key.get_pressed

Polling-based input recovers naturally on focus changes; key event-based code doesn't.

“OS doesn't always send keyup on focus changes. Polling is more resilient than events.”

For fast-paced action games, the polled-input pattern is safer than event-driven. Trade some convenience for resilience.

Related reading