title: python pygame input controls
body: <p>what are some ways i could get input from the user and move the player image? i can move the player image everytime i press W, A, S, or D but it only moves 1 pixel over. what can i do to make it move while a key is pressed?</p>
  
  <pre><code>import pygame
  from pygame.locals import *
  
  
  pygame.init()
  size = width, height = 640, 480
  screen = pygame.display.set_mode(size)
  pygame.display.set_caption("Gaben's Future Adventure")
  
  player = pygame.image.load("images/player.png")
  player_rect = player.get_rect()
  
  white = (255, 255, 255)
  black = (0, 0, 0)
  
  class World(object):
      def __init__(self):
          pass
  
  class Controls(object):
      def __init__(self):
          self.speed = 1
          self.keys = [False, False, False, False]
  
      def moveUp(self, player_rect):
          player_rect.y -= self.speed
      def moveLeft(self, player_rect):
          player_rect.x -= self.speed
      def moveRight(self, player_rect):
          player_rect.x += self.speed
      def moveDown(self, player_rect):
          player_rect.y += self.speed
  
      def update(self):
          pass
  
  def main():
      running = True
  
  
      while running:
          screen.fill(white)
  
  
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  running = False
                  print "Exiting game."
  
              if event.type == pygame.KEYDOWN:
                  if event.key == K_w:
                      print "W down"
                  elif event.key == K_a:
                      print "A down"
                  elif event.key == K_s:
                      Controls().moveDown(player_rect)
                      print "S down"
                  elif event.key == K_d:
                      Controls().moveRight(player_rect)
                      print "D down"
  
              if event.type == pygame.KEYUP:
                  if event.key == K_w:
                      print "W up"
                  elif event.key == K_a:
                      print "A up"
                  elif event.key == K_s:
                      print "S up"
                  elif event.key == K_d:
                      print "D up"
  
          screen.blit(player, player_rect)
          pygame.display.flip()
          print player_rect.x
          print player_rect.y
  main()
  </code></pre>