0

I am running K/Ubuntu 14.04 with ldmg and want to detect button pressure in pygame.

I am taking input from the keyboard and once the flag "include" is set, the window should close and we move onto the next in the list.

However the window refuses to close AND refuses to be closed manually using ALT + f4.

The code looks like:

    image_name = "something.jpg"

    image = pygame.image.load( image_name)

    white = (255, 255, 255)

    w = 640
    h = 480

    screen= pygame.display.set_mode((w,h))
    screen.fill((white))
    running = True

    while running:
        screen.fill((white))
            screen.blit(image,(0, 0))
            pygame.display.flip()

            ....
            pygame.event.wait()
            if pygame.event.peek():
            pressed=pygame.key.get_pressed()
            if pressed[K_LEFT]:
                include = 1
                running = False
           elif pressed[K_RIGHT]:
                 include = 0
                 running = False
    ...
    pygame.display.quit()
    sys.exit()

I know that most of this code works fine...The window appears Ok, but I just can't get it to close properly - perhaps it's not even taking the key data properly.

Anyone any thoughts?

PeterDz
  • 93
  • 1
  • 10
  • The code looks ok, do you see any exceptions printed out? – Bartlomiej Lewandowski Oct 07 '14 at 17:14
  • @Bartolmiej Hi,The short answer is "No". But what **does** happen is that any interaction with either keyboard or mouse gives "include = 1" and it then loops around trying to get more input, which suggests that whatever happens at 'pressed = ...' it assumes K_LEFT and doesn't get to K-Right or get to pygame.display.quit() – PeterDz Oct 07 '14 at 22:42
  • @Bartolomiej OK so I noticed that in the code above I hadn't initiated "include", so I set it to "1010" (no particular reason for the choice) and got it to write out the value of include...it gave 1010 irrespective of what I do and then it just sits waiting. – PeterDz Oct 07 '14 at 22:51
  • This means that you never receive data in `.get_pressed()` try calling `pygame.event.pump()` before – Bartlomiej Lewandowski Oct 08 '14 at 09:31

0 Answers0