import pygame from pygame.locals import * import sys pygame.init() display = pygame.display.set_mode((300, 300)) FPS_CLOCK = pygame.time.Clock() while 1: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() left, middle, right = pygame.mouse.get_pressed() if left: print("Left Mouse Key is being pressed") if event.type == pygame.MOUSEBUTTONDOWN: mouse_presses = pygame.mouse.get_pressed() if mouse_presses[0]: print("Left Mouse Key was clicked") flag = 1 while event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: if flag == 1: pygame.mouse.set_visible(False) flag = 0 elif flag == 0: pygame.mouse.set_visible(True) flag = 1 class Player: def __init__(self): self.rect = pygame.draw.rect(display, (255, 0, 0), (100, 100, 100, 100)) player = Player() if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW) if event.key == pygame.K_2: pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND) while 1: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse clicked on the player") if event.type == pygame.MOUSEBUTTONUP: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse released on the player") pygame.display.update() FPS_CLOCK.tick(30)