fceux/get_key.py

35 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import sys
try:
import pygame
from pygame.locals import *
has_pygame = True
except ImportError:
self.has_pygame = False
2008-06-28 19:19:06 +00:00
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. . .")
2008-06-28 19:19:06 +00:00
def get_key(self):
while 1:
for event in pygame.event.get():
if event.type == KEYDOWN:
pygame.display.quit()
return event.key
2008-12-05 08:44:43 +00:00
# TODO: Make work with joystick. Do buttons first.
if event.type == JOYBUTTONDOWN:
pygame.display.quit()
# TODO: Make sure we're returning the data we need
# for config file here. I'm not sure if this is
# the correct data.
return event.joy, event.button
2008-06-28 19:19:06 +00:00
if __name__ == "__main__":
kg = KeyGrabber()
print kg.get_key()