Modularized the sdl KeyGrabber

This commit is contained in:
punkrockguy318 2008-06-28 19:19:06 +00:00
parent 2db6590fbd
commit 508734aee6
1 changed files with 18 additions and 10 deletions

View File

@ -3,15 +3,23 @@ import pygame
import sys
from pygame.locals import *
pygame.init()
width = 300
height = 100
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Press any key. . .")
while 1:
for event in pygame.event.get():
if event.type == KEYDOWN:
print event.key
sys.exit(event.key)
class KeyGrabber:
""" KeyGrabber is a wrapper that gets an SDL key from the user using pygame """
def __init__(self, width=300, height=100):
pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Press any key. . .")
def get_key(self):
while 1:
for event in pygame.event.get():
if event.type == KEYDOWN:
#print event.key
pygame.display.quit()
return event.key
if __name__ == "__main__":
kg = KeyGrabber()
print kg.get_key()