0

I was wondering if there is a way to set up a 1 button mode that switches the function of my controller to use the left or right stick depending on if the button was press or not using pygame?

Basically press button = control left joystick press button (again) = control right joystick

currently I have tried running this

joysticks = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
events = pygame.event.get()
with self.lock:
    for event in events:   
       " Detect middle x-box button"
       if event.type == pygame.JOYBUTTONDOWN:
          if event.button == 8:
             t = pygame.event.get()
             for r in t:
                if r.type == pygame.JOYAXISMOTION:
        # " Left stick"
                    if r.axis == 0:
                       if r.value > 1:
                           r.value = 1
                       if r.value < -1:
                           r.value = -1
                       print(r.value)
                       self.left_stick.update_x(r.value)
                    if r.axis == 1:
                       if r.value > 1:
                           r.value = 1
                       if r.value < -1:
                           r.value = -1
                       print(r.value)
                       self.left_stick.update_y(r.value)
              self.middle_led_ring_button.update(1)

This detects that the xbox button when is press and should then detect if the jostick is moved, but it doesn't. I think is because it has 2 events in it self?

I am looking for something like

       if event.type == pygame.JOYBUTTONDOWN:
          if event.button == 8:
             if button_press: 
                c = joystick.value
                move_left_stick(c)
             if button_press_again:
                c = joystick.value
                move_right_stick(c)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

0 Answers0