Why did this work?
Im writing and game in python using pygame. Im working on hero movement and couldnt get my hero to move by simply holding down a directional key I had to continually tap it. I solved the problem by adding a line of code:"pygame.key.set_repeat(True)" i added this code under the line that says keys = pygame.key.get_pressed() and it didnt work. Then i decided to add it above the main loop as you will see and it worked. So problem is fixed but i need to know why. Heres the code: import pygame pygame.init() win = pygame.display.set_mode((500,500)) pygame.display.set_caption("My First Pygame") x = 50 y = 425 width = 40 height = 60 vel = 5 isJump = True jumpCount = 10 pygame.key.set_repeat(True) run = True while run: pygame.time.delay(100) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and x > vel: x -= vel