#keyPresses.py # #Key Press Events # import pygame screen = pygame.display.set_mode((640, 480)) #Pygame screen @ 640 X 480 pygame.display.set_caption("keyPresses.py") #Pygame window title LINE_COLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] #Red, Green, and Blue RGB Values x = 0 #LINE_COLORS[] Subscript BG_COLOR = (0, 0, 0) #Black RGB Value clock = pygame.time.Clock() #Pygame clock FPS = 60 #60 FPS running = True #Main game loop flag variable while running: #For loop to check pygame events. The nested if statements check #for either the quit event or the keydown events. After it finds a #keyboard event it specifically looks for the down button. When it #finds the down button it cycles through the RGB values in LINE_COLORS[] #to change the background color. for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: if x == 3: x = 0 screen.fill(LINE_COLORS[x]) x += 1 pygame.display.flip() #Updates display clock.tick(FPS) #Sets the framerate