title: Increase a variable just by one when a key is pressed
body: <p>I have a variable state counter which I want to decrease by one, when a key <code>a</code> is pressed and increase by one when a <code>d</code> key is pressed.</p>
  
  <p>I took an inspiration in question: Increase just by one when a key is pressed, but my code did not work as expected, when I reset the <code>was_pressed</code> variable to <code>false</code> the state counter began to increase itself.</p>
  
  <pre><code>running = True
  state_counter = 0
  number_of_states = 0
  was_pressed = False
  
  import pygame
  
  while running:
      for event in pygame.event.get():
          if event.type == QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
          # The user closed the window or pressed escape
          running = False
  
          if event.type == KEYDOWN and event.key==K_a:
              if not was_pressed:
                  state_counter -= 1
                  print("state_counter %d times"%state_counter)
                  was_pressed = True
              else:
                  was_pressed = False
  
          elif event.type == KEYDOWN and event.key == K_d:
              if not was_pressed:
                  state_counter += 1
                  print("state_counter %d times"%state_counter)
                  was_pressed = True
              else:
                  was_pressed = False
  pygame.quit()
  print('Done!, state counter is: ', state_counter)
  </code></pre>
  
  <p>The problem is that I need the variable both increment and decrement (thats the difference from the mentioned question) and of course I need the variable to change each and every time I press the key (which is probably the case of the previous question as well but I could not achieve that). I also cannot us <code>time.sleep()</code> because I don't want the program to sleep.</p>
  
  <p>Any help appreciated, thank you very much in advance.</p>