Modularized the sdl KeyGrabber
This commit is contained in:
parent
2db6590fbd
commit
508734aee6
28
get_key.py
28
get_key.py
|
@ -3,15 +3,23 @@ import pygame
|
||||||
import sys
|
import sys
|
||||||
from pygame.locals import *
|
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:
|
class KeyGrabber:
|
||||||
for event in pygame.event.get():
|
""" KeyGrabber is a wrapper that gets an SDL key from the user using pygame """
|
||||||
if event.type == KEYDOWN:
|
def __init__(self, width=300, height=100):
|
||||||
print event.key
|
pygame.init()
|
||||||
sys.exit(event.key)
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue