detect key press in python?
Question: I am making a stopwatch type program in python and I would like to know how to
detect if a key is pressed (such as p for pause and s for stop), and I would
not like it to be something like raw_input that waits for the user's input
before continuing execution. Anyone know how to do this in a while loop?

Also, I would like to make this cross-platform, but if that is not possible,
then my main development target is linux


Answer: Use PyGame to have a window and then you can get the key events.

**For the letter`p`:**

    
    
    import pygame, sys
    import pygame.locals()
    
    pygame.init()
    BLACK = (0,0,0)
    WIDTH = 1280
    HEIGHT = 1024
    windowSurface = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
    
    windowSurface.fill(BLACK)
    
    while True:
        events = pygame.event.get()
        for event in events:
            if event.key == pygame.K_p:
                 #Do what you want to here
                 pass
            if event.type == QUIT:
                 pygame.quit()
                 sys.exit()
    

