title: Pygame keyboard input event lag
body: <p>I am hitting an issue after writing a small program with <strong>pygame</strong>. The program takes split .GIF animations and loads the images(frames of the gif) via:</p>
  
  <pre><code>pygame.image.load(filename)
  </code></pre>
  
  <p>This returns a pygame surface object which is then appended to an array. The program loads about <strong>15 frames</strong> to an array, using <strong>6 arrays</strong> in total.</p>
  
  <p>The problem I am having is when accepting input through my <strong>while loop.</strong> The loop plays its idle animation and running animation fine, <em>however</em>, on accepting input from the keyboard (grabbing input from pygame's event list...)</p>
  
  <p><code>for event in pygame.event.get():</code> via <code>pygame.KEYDOWN</code></p>
  
  <p>There is very noticeable lag, making for <strong>unresponsive animation set switching</strong>. If I am to make a game using this method, it will have to be fixed. I'm sure my code is inefficient, but it should suffice not to create pauses. Any help would be fantastic.</p>
  
  <p>My guess? <code>pygame.clock.tick()</code> is creating some sort of <strong>event lag</strong>, but I am unsure as to how to go about fixing this, if event lag is even the case.</p>
  
  <p>Here is the loop that I suspect to be problematic:</p>
  
  <pre><code>while running == 2:
  pygame.display.flip()
  #mouse = pygame.mouse.get_pos()
  #events = pygame.event.get()
  #(pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP)
  for event in pygame.event.get():
  #event = pygame.event.wait()
      if event.type == pygame.QUIT:
          sys.exit(0)
      elif event.type == pygame.KEYDOWN:
          print event.key
          wait = 0
          if event.key == pygame.K_d:
              tmpcache = wr
              lastkey = "wr"
          elif event.key == pygame.K_a:
              tmpcache = wl
              lastkey = "wl"
      elif event.type == pygame.KEYUP:
          wait = 1
          if lastkey == "wr":
              tmpcache = sr
          elif lastkey == "wl":
              tmpcache = sl
  
  if wait == 1:           
      for frame in tmpcache:
          screen.blit(test, (0,0))
          screen.blit(frame, (currentchar.posx, currentchar.posy))
          pygame.display.flip()
          clock.tick(charfps)
  
  else:
      for frame in tmpcache:
          screen.blit(test, (0,0))
          screen.blit(frame, (currentchar.posx, currentchar.posy))
          pygame.display.flip()
          clock.tick(charfps)
  </code></pre>
  
  <p>some variables not shown here, but are used:</p>
  
  <p><code>charfps = 30</code><br>
  <code>currentchar.posx, currentchar.posy</code> are both <strong>tuples</strong> set at <code>(300, 240)</code>  </p>