import pygame # Initialize pygame pygame.init() # Initialize the joystick pygame.joystick.init() if pygame.joystick.get_count() == 0: print("No joystick found. Make sure your controller is connected.") exit() # Initialize the first joystick (index 0) joystick = pygame.joystick.Joystick(0) joystick.init() try: while True: for event in pygame.event.get(): if event.type == pygame.JOYAXISMOTION: # Handle joystick axis motion axis = event.axis value = event.value print(f"Axis {axis}: {value:.2f}") elif event.type == pygame.JOYBUTTONDOWN: # Handle button press button = event.button print(f"Button {button} pressed") elif event.type == pygame.JOYBUTTONUP: # Handle button release button = event.button print(f"Button {button} released") except KeyboardInterrupt: pass # Clean up pygame.quit()