Pages

marți, 17 februarie 2009

PyGame : Keyboard on pygame

This is a short example of how to use the keyboard in pygame.

import os
import sys
import pygame
from pygame import *
def main():
   pygame.init()
   ecran = pygame.display.set_mode((640, 480))
   ruleaza= True
   action = "Help!"
   while ruleaza is True:
       for event in pygame.event.get():
           if event.type == QUIT:
               ruleaza == False
           elif event.type == KEYDOWN:
               if event.key == K_ESCAPE:
                   ruleaza = False
               elif event.key == K_LEFT:
                   action="L"
               elif event.key == K_RIGHT:
                   action="R"
           print action
main()