Pygame doesn't catch keydown events on mac
Question: When I am trying to catch keys pressed, they are printed in Terminal, but not
caught by pygame and the script. Script is executed as follows:

    
    
    >>>import scriptname
    >>>scriptname.wa()
    

scriptname file: import pygame from pygame.locals import *

    
    
    def wa():
        pygame.init()
        screen = pygame.display.set_mode((640, 480), 0, 32)
    
        alive_key = True
    
        while alive_key:
            for event in pygame.event.get():
                if event.type == QUIT:
                    alive_key = False
                elif event.type == KEYDOWN and event.key == K_q:
                    print '\nThis is not happening\n'
    
            screen.fill((0, 0, 0))
    
            if pygame.mouse.get_pressed()[0]:
                pygame.event.post(
                  pygame.event.Event(KEYDOWN, key=K_q, mod=0, unicode=u'q'))
    
            pygame.display.update()
    
        pygame.quit()
    

If events are created on mouse press (as presented in code), they work.

I am using OS X 10.8.5, python 2.7, pygame2.7 1.9.1. Everything works
perfectly in Windows 7 with similar configuration.

Thanks!


Answer: change your code to:

    
    
    elif event.type == KEYDOWN or event.type == pygame.KEYDOWN:
        # for testing purpose
        print event 
    
        if event.key == pygame.K_q:
            print '\nThis is not happening\n
    

I'm using OS X 10.9.5, python 2.7.7, pygame-1.9.2pre-py2.7-macosx10.7. Had the
similar problem as yours earlier. I found this solution here:
<http://content.gpwiki.org/index.php/Python:Pygame_keyboard_input>

I think this is not mac's fault, possibly.

