Skip to content

Instantly share code, notes, and snippets.

@cgdougm
Last active October 9, 2019 14:11
Show Gist options
  • Save cgdougm/7254e439fb4ab0136665 to your computer and use it in GitHub Desktop.
Save cgdougm/7254e439fb4ab0136665 to your computer and use it in GitHub Desktop.
[PyGame event loop] Mouse and keyboard event types #boilerplate #pygame #eventloop
import pygame
pygame.init()
screen = pygame.display.set_mode( (800,600) )
surface = pygame.Surface(screen.get_size())
screen.fill( (75,85,85) )
cont = True
while cont:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print "QUIT"
cont = False
elif event.type == pygame.KEYDOWN:
print "KEYDOWN"
print " -->",event.key
if event.key == 27: # escape
cont = False
break
elif event.type == pygame.KEYUP:
print "KEYUP"
elif event.type == pygame.MOUSEMOTION:
print "MOUSEMOTION"
elif event.type == pygame.MOUSEBUTTONUP:
print "MOUSEBUTTONUP"
elif event.type == pygame.MOUSEBUTTONDOWN:
print "MOUSEBUTTONDOWN"
print " ->",pygame.mouse.get_pressed()
pygame.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment