title: Pygame move shape with keyboard input
body: <p>Created first pygame program to move a rectangle around the screen. Can't figure out why the shape is not actually moving. I had it working before with a simple</p>
  
  <pre><code>  shape = shape.move(speed)
  </code></pre>
  
  <p>But now with keyboard inputs the shape does not move. I used some print statements to make sure that the function checkKeys is rendering my keypresses (and the changes in speed that they make), and it is. However the shape still does not move.</p>
  
  <pre><code>import sys, pygame
  pygame.init()
  
  size = width, height = 320, 240
  black = (0, 0, 0)
  red = (255, 0, 0)
  pygame.display.set_caption("Object Move Test")
  clock = pygame.time.Clock()
  
  def main():
      screen = pygame.display.set_mode(size)
      shape = pygame.draw.rect(screen, (255, 0, 0), (200, 100, 10, 10,))
      ballrect = pygame.Surface((10,10), 0, shape)
  
      def checkKeys(speedY, speedX, shape):
          key = pygame.key
          pygame.event.pump()
          if key.get_pressed()[pygame.K_UP] and speedY &lt; 1:
              speedY = speedY - 1
              #print 'UP'
          if key.get_pressed()[pygame.K_DOWN] and speedY &gt; -1:
              speedY = speedY - 1
              #print 'DOWN'
          if key.get_pressed()[pygame.K_LEFT] and speedX &gt; -1:
              speedX = speedX - 1
              #print 'LEFT'
          if key.get_pressed()[pygame.K_RIGHT] and speedX &lt; 1:
              speedX = speedX + 1
              #print speedX
          speed = [speedX, speedY]
          #print speed
          moveShape(speed, shape)
  
      def moveShape(speed, shape):
          print speed
          shape = shape.move(speed)
          if shape.left &lt; 0 or shape.right &gt; width:
              speed[0] = -speed[0]
          if shape.top &lt; 0 or shape.bottom &gt; height:
              speed[1] = -speed[1]
  
      while 1:
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  sys.exit()
  
          speedX, speedY = (0, )*2 
          speed = [speedX, speedY]        
          screen.fill((255,255,255))
          clock.tick(20)
          checkKeys(speedX, speedY, shape)
  
          screen.blit(ballrect, shape)
          pygame.display.flip()
  
  if __name__ == '__main__':
      main()
  </code></pre>