External Exam Download Resources Web Applications Games Recycle Bin

event MOUSE

rapid clicker.py

import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
done = False
while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    elif event.type == pygame.KEYDOWN:
      if event.key == pygame.K_ESCAPE:
        done = True
    elif event.type == pygame.MOUSEBUTTONDOWN: #single click
        print(event.button) #int: 1-left, 2-middle, 3-right, 4-scrollup, 5-scrolldown
      
  buttons = pygame.mouse.get_pressed() #polls current state of every button
  if buttons[2]: #if right mouse button is held down..
    print(buttons) #tuple(leftbutton[0], middlebutton[1], rightbutton[2])
 
  pygame.display.flip()
  
pygame.quit()