Feb-23-2019, 01:39 PM
Also with KEYUP and KEYDOWN. Mod is pass to the event.
import pygame class Game: def __init__(self, caption, width, height): # Basic pygame setup pygame.display.set_caption(caption) self.rect = pygame.Rect(0, 0, width, height) self.surface = pygame.display.set_mode(self.rect.size) self.clock = pygame.time.Clock() def mainloop(self): self.running = True while self.running: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.mod & pygame.KMOD_SHIFT: # event.unicode handles shift itself print('Shift', event.unicode) else: print('Key pressed', event.unicode) elif event.type == pygame.QUIT: self.running = False self.surface.fill(pygame.Color('Darkblue')) pygame.display.update() self.clock.tick(30) if __name__ == '__main__': pygame.init() game = Game('Example', 800, 600) game.mainloop() pygame.quit()
99 percent of computer problems exists between chair and keyboard.