title: How to efficiently hold a key in Pygame?
body: <p>I've found two related questions:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/20157323/pygame-hold-key-down-causes-an-infinite-loop">Pygame hold key down causes an infinite loop</a></li>
  <li><a href="https://stackoverflow.com/questions/13671357/pygame-on-hold-button-down">pygame - on hold button down</a></li>
  </ul>
  <p>But I want to be specific. How to?</p>
  <pre><code>while not done:
      for e in event.get():
          if e.type == KEYDOWN:
              keys = key.get_pressed()
              if e.type == QUIT or keys[K_ESCAPE]:
                  done = True
              if keys[K_DOWN]:
                  print &quot;DOWN&quot;
  </code></pre>
  <p>When I press the down arrow, it prints, but it prints just once. If I want to print it another time, I need to press it again.</p>
  <p>If I use the while keyword instead,</p>
  <pre><code>while keys[K_DOWN]:
      print &quot;DOWN&quot;
  </code></pre>
  <p>I get an infinite loop for some obscure reason.</p>
  <p>This logical alternative is also useless:</p>
  <pre><code>if ((e.type == KEYDOWN) and keys[K_DOWN]):
      print &quot;DOWN&quot;
  </code></pre>
  <p>And there is this other one that somehow cleans the events and you can use while:</p>
  <pre><code>while not done:
      for e in event.get():
          if e.type == KEYDOWN:
              keys = key.get_pressed()
              if e.type == QUIT or keys[K_ESCAPE]:
                  done = True
              while keys[K_DOWN]:
                  print &quot;DOWN&quot;
                  event.get()
                  keys = key.get_pressed()
  </code></pre>
  <p>But you press the down key for less than one second and it prints thousands of times. (Moving a player would be impossible, and adjusting clock for this does not seem to be the right way to deal with it (And I've tried and I've failed miserably.)).</p>
  <p>To press and execute the block thousands of times is useless. What I want, is to press the key and keep going with the action while I don't release it, within the defined game clock speed.</p>