code: def _detect_gamepads(self):
          
          state = XinputState()
          # Windows allows up to 4 gamepads.
          for device_number in range(4):
              res = self.xinput.XInputGetState(
                  device_number, ctypes.byref(state))
              if res == XINPUT_ERROR_SUCCESS:
                  # We found a gamepad
                  device_path = (
                      "/dev/input/by_id/" +
                      "usb-Microsoft_Corporation_Controller_%s-event-joystick"
                      % device_number)
                  self.gamepads.append(GamePad(self, device_path))
                  continue
              if res != XINPUT_ERROR_DEVICE_NOT_CONNECTED:
                  raise RuntimeError(
                      "Unknown error %d attempting to get state of device %d"
                      % (res, device_number))
docs: Find gamepads.