To clarify a bit more, I think this is the crux of the issue:
Take the following snippet:
If you want something to fire immediately on an event you will need it to, well, fire immediately on that event:
Take the following snippet:
for event in pg.event.get(): if event.type == pg.MOUSEBUTTONDOWN: mouse_clicked = True elif event.type == pg.MOUSEBUTTONUP: mouse_clicked = False if mouse_clicked: run_on_click()You seem to be assuming that if the mouse is clicked, the function at the bottom will always run. This isn't the case. The event queue can potentially have both a MOUSEBUTTONDOWN and MOUSEBUTTONUP event in it at the same time. This means that by the time your event loop is finished your mouse_clicked variable could have been set to True and then back to False before reaching the end of the code and running the function in the conditional.
If you want something to fire immediately on an event you will need it to, well, fire immediately on that event:
for event in pg.event.get(): if event.type == pg.MOUSEBUTTONDOWN: run_on_click()Again as I said previously this comes down to the fact that the way you are trying to design the key handler is currently not ideal.