Reputation: 91
This is my code I have for a game I am making and I manage to get the first text written to the screen then it manages to print the events but it won't run the second part of the code. I am assuming that if event.type == pygame.K_RETURN:
doesn't work. I am either doing something wrong or it's not working.
while True:
for event in pygame.event.get():
#print(event)
if event.type==pygame.KEYDOWN:
print("key pressed")
if event.type == pygame.K_RETURN:
print(event)
print("enter key pressed")
screen.fill(blue)
textSurf, textRect = text_objects(t2, smallText)
textRect.center = ((700),(100))
screen.blit(textSurf, textRect)
pygame.display.update()
pygame.display.update()
Upvotes: 4
Views: 605
Reputation: 20488
Yes, if event.type == pygame.K_RETURN:
should be if event.key == pygame.K_RETURN:
.
The pygame.KEYDOWN
and pygame.KEYUP
event types have a key
attribute that is used to check which key was pressed.
You can find a list of event types and their attributes in the docs: http://www.pygame.org/docs/ref/event.html
Upvotes: 4