Last active
October 9, 2019 14:11
-
-
Save cgdougm/7254e439fb4ab0136665 to your computer and use it in GitHub Desktop.
[PyGame event loop] Mouse and keyboard event types #boilerplate #pygame #eventloop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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