In Pygame, you can set repeated (held down) Key detection with pygame.key.set_repeat().
In my case, I want to mix keys that can be held down and keys that will only be recognized once. Specifically, I want to be able to Move (by holding down key(s)), but I want to require one key press per Fire Missile.
To be clearer, I want to recognize held-down key presses for movement keys (Up, Down, Left, Right, etc.) only. Other keys, when held down, should only be recognized once.
You can keep a state tracker for the keys you only want to recognize once per press – set a flag to
Truewhen you see a KEYDOWN event, and then set it toFalseagain when you see a matchingKEYUP. Then only respond to aKEYDOWNevent if the flag wasn’t alreadyTrue.The other option is that you can keep a state tracker for the keys you do want to repeat and just poll that state every so often (e.g. every X milliseconds, see if the key is marked as ‘down’ and if so, do whatever should be done for that keypress).