[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] [mac OS Sierra] key event not activated


When I ran the code below on mac os sierra, both of console window and pygame.display window kept focused. Then I typed something, letters went directly to console without going through the key events in the program. Escape key also didn't let me out of the program.
However people on irc (all on linux) couldn't reproduce the problem, assuming this could be one of the mac-specific problems.

I am using python 3.5.2(pyenv install) with pygame 1.9.2b6. Are there any way to avoid this problem?
(please excuse my English mistakes if any)

import pygame


pygame.display.set_mode((100, 100))

print('ready. ' + pygame.ver)
running = True
clock  = pygame.time.Clock()
while running:
    for e in pygame.event.get():
    # e = pygame.event.wait()
        if e.type == pygame.QUIT:
            running = False
        elif e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                running = False
                keyname = pygame.key.name(e.key)
                print('key is pressed: ' + keyname)
        elif e.type == pygame.KEYUP:
            keyname = pygame.key.name(e.key)
            print('key is released: ' + keyname)
    # pygame.display.update()