code: def handle_input(self):
          
          poll = pygame.event.poll
  
          event = poll()
          while event:
              if event.type == QUIT:
                  self.running = False
                  break
  
              elif event.type == KEYDOWN:
                  if event.key == K_ESCAPE:
                      self.running = False
                      break
  
                  elif event.key == K_EQUALS:
                      self.map_layer.zoom += .25
  
                  elif event.key == K_MINUS:
                      value = self.map_layer.zoom - .25
                      if value > 0:
                          self.map_layer.zoom = value
  
              # this will be handled if the window is resized
              elif event.type == VIDEORESIZE:
                  init_screen(event.w, event.h)
                  self.map_layer.set_size((event.w, event.h))
  
              event = poll()
  
          # using get_pressed is slightly less accurate than testing for events
          # but is much easier to use.
          pressed = pygame.key.get_pressed()
          if pressed[K_UP]:
              self.hero.velocity[1] = -HERO_MOVE_SPEED
          elif pressed[K_DOWN]:
              self.hero.velocity[1] = HERO_MOVE_SPEED
          else:
              self.hero.velocity[1] = 0
  
          if pressed[K_LEFT]:
              self.hero.velocity[0] = -HERO_MOVE_SPEED
          elif pressed[K_RIGHT]:
              self.hero.velocity[0] = HERO_MOVE_SPEED
          else:
              self.hero.velocity[0] = 0
docs: Handle pygame input events