tags:

views:

20

answers:

1

how can I interrupt python execution with a key and continue to run when the key is pressed again ?

thanks

A: 

If you're using pygame, you can check for the key event and use a boolean switch.

def check_pause(self):
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_p:
                self.pause = not self.pause

Something like that, attached to

while True:
    self.check_pause()
    if self.pause:
        continue
    # Main loop of program goes here.
Nathon