import pygame

pygame.init()

screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Pygame All Events Example")

font = pygame.font.Font(None, 30)
event_log = []

running = True
while running:
    for event in pygame.event.get():
        event_log.insert(0, f"Event: {pygame.event.event_name(event.type)} - {event.__dict__}")
        if len(event_log) > 10:  # Keep only the last 10 events for display
            event_log.pop()

        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            print(f"KEYDOWN: Key={pygame.key.name(event.key)}, Modifiers={event.mod}, Unicode='{event.unicode}', Scancode={event.scancode}")
        elif event.type == pygame.KEYUP:
            print(f"KEYUP: Key={pygame.key.name(event.key)}, Modifiers={event.mod}")
        elif event.type == pygame.MOUSEMOTION:
            print(f"MOUSEMOTION: Pos={event.pos}, Relative={event.rel}, Buttons={event.buttons}")
        elif event.type == pygame.MOUSEBUTTONDOWN:
            print(f"MOUSEBUTTONDOWN: Pos={event.pos}, Button={event.button}")
        elif event.type == pygame.MOUSEBUTTONUP:
            print(f"MOUSEBUTTONUP: Pos={event.pos}, Button={event.button}")
        elif hasattr(pygame, 'MOUSEWHEEL') and event.type == pygame.MOUSEWHEEL:
            print(f"MOUSEWHEEL:X={event.x}, Y={event.y}, Precise X={event.precise_x}, Precise Y={event.precise_y}, Flipped={event.flipped}")
        elif event.type == pygame.ACTIVEEVENT:
            print(f"ACTIVEEVENT: Gain={event.gain}, State={event.state}")
        elif event.type == pygame.VIDEORESIZE:
            print(f"VIDEORESIZE: Size=({event.w}, {event.h})")
            screen = pygame.display.set_mode(event.size, pygame.RESIZABLE)
        elif event.type == pygame.VIDEOEXPOSE:
            print("VIDEOEXPOSE")
        elif hasattr(pygame, 'WINDOWEVENT') and event.type == pygame.WINDOWEVENT:
            print(f"WINDOWEVENT: Event={pygame.event.event_name(event.event)}, Data1={event.data1}, Data2={event.data2}")
        elif pygame.joystick.get_count() > 0:
            for i in range(pygame.joystick.get_count()):
                joystick = pygame.joystick.Joystick(i)
                joystick.init()
                if event.type == pygame.JOYAXISMOTION and event.joy == joystick.get_id():
                    print(f"JOYAXISMOTION (Joystick {joystick.get_id()}): Axis={event.axis}, Value={event.value}")
                elif event.type == pygame.JOYBALLMOTION and event.joy == joystick.get_id():
                    print(f"JOYBALLMOTION (Joystick {joystick.get_id()}): Ball={event.ball}, Relative={event.rel}")
                elif event.type == pygame.JOYHATMOTION and event.joy == joystick.get_id():
                    print(f"JOYHATMOTION (Joystick {joystick.get_id()}): Hat={event.hat}, Value={event.value}")
                elif event.type == pygame.JOYBUTTONDOWN and event.joy == joystick.get_id():
                    print(f"JOYBUTTONDOWN (Joystick {joystick.get_id()}): Button={event.button}")
                elif event.type == pygame.JOYBUTTONUP and event.joy == joystick.get_id():
                    print(f"JOYBUTTONUP (Joystick {joystick.get_id()}): Button={event.button}")
        elif event.type >= pygame.USEREVENT:
            print(f"USEREVENT: Type={event.type}, Data={event.__dict__}")
        elif hasattr(pygame, 'TEXTINPUT') and event.type == pygame.TEXTINPUT:
            print(f"TEXTINPUT: Text='{event.text}'")
        elif hasattr(pygame, 'TEXTEDITING') and event.type == pygame.TEXTEDITING:
            print(f"TEXTEDITING: Text='{event.text}', Start={event.start}, Length={event.length}")
        elif hasattr(pygame, 'FINGERDOWN') and event.type == pygame.FINGERDOWN:
            print(f"FINGERDOWN: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}")
        elif hasattr(pygame, 'FINGERUP') and event.type == pygame.FINGERUP:
            print(f"FINGERUP: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}")
        elif hasattr(pygame, 'FINGERMOTION') and event.type == pygame.FINGERMOTION:
            print(f"FINGERMOTION: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}")
        elif hasattr(pygame, 'AUDIODEVICEADDED') and event.type == pygame.AUDIODEVICEADDED:
            print(f"AUDIODEVICEADDED: Which={event.which}, Is Capture={event.iscapture}")
        elif hasattr(pygame, 'AUDIODEVICEREMOVED') and event.type == pygame.AUDIODEVICEREMOVED:
            print(f"AUDIODEVICEREMOVED: Which={event.which}, Is Capture={event.iscapture}")
        elif event.type == pygame.SYSWMEVENT:
            print(f"SYSWMEVENT: Message={event.msg}, Data1={event.data1}, Data2={event.data2}")

    screen.fill((255, 255, 255))  # Fill the screen with white

    y_offset = 10
    for log_entry in event_log:
        text_surface = font.render(log_entry, True, (0, 0, 0))
        screen.blit(text_surface, (10, y_offset))
        y_offset += 20

    pygame.display.flip()

pygame.quit()