Noobcoder Noobcoder -4 years ago 49
Python Question

How do I make it so that when I press a key an image pops up and stays there until i let go?

I am basically trying to do what the question says but its not happening. Can anyone explain why?

if event.type == pygame.KEYDOWN:
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
screen.blit(player_1, [170, 333])
if keys[pygame.K_d]:
screen.blit(player_1, [331, 500])
if keys[pygame.K_s]:
screen.blit(player_1, [170, 665])
if keys[pygame.K_a]:
screen.blit(player_1, [10, 500])
if keys[pygame.K_UP]:
screen.blit(player_2, [195, 333])
if keys[pygame.K_RIGHT]:
screen.blit(player_2, [356, 500])
if keys[pygame.K_DOWN]:
screen.blit(player_2, [196, 665])
if keys[pygame.K_LEFT]:
screen.blit(player_2, [35, 500])

Answer Source

Instead of holding your key down. Try using a Boolean statement bonded to the key you want to pop up an image. Would look something similar to this Keys[pygame.K_UP] = false If Keys[pygame.K_UP] == true: Print "(insert image url here)" Else (Do nothing)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download