while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print("Pressed Space")
else:
if event.key == pygame.K_w:
print("Pressed w")
screen.blit(background, background_rect)
pygame.display.update()
I have a Mac and for some reason its not registering any of my keyboard inputs except for left shift. How can I fix this? (Pygame)
I believe your error is because of incorrect indentation. The event checking in the for event in pygame.event.get()
loop needs to be inside the loop to run on all events.
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# moved this in one level --->
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print("Pressed Space")
elif event.key == pygame.K_w: # no need for an "else" then an "if"
print("Pressed w")
screen.blit(background, background_rect)
pygame.display.update()