[clug] Building a simple UI with pygame, keystrokes and a window focus problem
hal at ashburner.info
Tue Feb 1 03:37:50 MST 2011
I'm knocking up a quick and dirty dedicated do-hickey booth thing for a
friend's art project. This is going to run on a dedicated laptop.
I'm using pygame and an i-pac keyboard controller
#I want sound effects when switches hit. Ok easy
sound1 = pygame.mixer.Sound("foo.ogg")
#switches hit, going via the ipac thingy should be handled as
for event in pygame.events.get():
if event.type == KEYDOWN:
#a switch was hit!
#somewhere in the initialisation I'm doing:
window = pygame.display.set_mode((width, height)), pygame.FULLSCREEN)
#which makes sure pygame gets the keystrokes.
#All good, right up until one of the things I want to do is launch
cheese as a photobooth kind of deal.
if not cheese:
cheese = subprocess.Popen("/usr/bin/cheese")
cheese = None
#which, as you probably saw a lot faster than me because I actually
coded & tested it before realising, takes focus away from the pygame
app, thereby swallowing all keystrokes.
So I just want to create a very very simple and stupid UI that responds
to keystrokes, on which it makes a noise or launches/kills a process. I
want all keystrokes to be handled by this UI and not captured by the any
Am I doing it all wrong using pygame? Suggestions with or without pygame?
More information about the linux