Pygame not handling keyboard or mouse events properly
Question: I have recently reinstalled pygame on my Mac. I installed pygame 1.9.2a0. I
have the same version on my windows and the same version before on this very
Mac. But I am getting strange results with this new installation. I noticed
that all the draw commands work fine, but for some reason clicking on the
pygame window does not. The window opens up in the background, it is not
normal but it is not a big problem. But then all key presses are redirected to
the terminal/IDE (which ever the application was run from). I have attached
below a very simple program that I am testing with. The program just looks for
the escape key. Note that this works just fine on my windows machine.

TL;DR: Why are keypresses sent to the terminal and not to the pygame window's
event loop when the window is selected.

I am baffled by this issue mostly because I have not experienced any issues
like this before. I am not really sure how to debug this problem either. If
additional information is needed I would be happy to provide them.

    
    
    import pygame
    import sys
    from pygame.locals import *
    
    pygame.init()
    size = width, height = 100, 100
    screen = pygame.display.set_mode(size)
    
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.event.post(pygame.event.Event(QUIT))
    
        screen.fill((30, 30, 30))
        pygame.display.flip()
    

For the curious:

  * MacOSX 10.10.1
  * Python 3.4.2 (via pyenv)
  * Pygame: 1.9.2a0

**Update:**

I had a theory that there was some sort of issue that appeared in one of the
newer commits. So I decided to pull their repository down and revert to
previous commits. It seemed rather promising, especially since they had a "big
bang" merge of 8 or so pull requests in early January of 2015. So I pulled the
repository back to the commit before this massive merging happened and the
issue was exactly the same. I decided to do this to a couple of other commits
(before and after the merge location) and still no change. Any suggestions?


Answer: It looks like you are trying to make a shutdown key without having to use the
X in the corner. This is what I did to fix that when I needed to.

    
    
    key = pygame.key.get_pressed()
    running = 1
    
    while running:
      for event in pygame.event.get():
    
    if event.type == QUIT:
        pygame.quit()
        running = 0
    elif key[pygame.K_ESCAPE]:
        pygame.quit()
        running = 0
    

hope this helps. by the way the escape key doesn't always work so maybe set it
to a different key bind. And for the mouse you need to check the position of
the mouse.

    
    
    def run():
        pos = pygame.mouse.get_pos()
    
    #check_events
    check_events(pos)
    

