Last active
December 10, 2015 23:18
-
-
Save hortonew/4507874 to your computer and use it in GitHub Desktop.
Pygame - Mouse Handling
This file contains 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, sys | |
running = True | |
pygame.init() | |
screen = pygame.display.set_mode((800,600)) | |
clock = pygame.time.Clock() | |
def handleEvents(): | |
for event in pygame.event.get(): | |
#print current mouse position | |
if event.type == pygame.MOUSEMOTION: | |
print pygame.mouse.get_pos() | |
#when a user presses a mouse button, print which one and where the mouse is | |
if event.type == pygame.MOUSEBUTTONDOWN: | |
print "{0} pressed at: {1},{2}.".format(pygame.mouse.get_pressed(), pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]) | |
if __name__ == "__main__": | |
while running: | |
handleEvents() | |
pygame.display.flip() | |
clock.tick(30) | |
pygame.quit() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment