piborg / Gamepad

A simple library for getting game controller and joystick inputs into Python in Linux.
MIT License
100 stars 27 forks source link

Add Controller Support #7

Open Dev5H0 opened 2 years ago

Dev5H0 commented 2 years ago
ploiu commented 2 months ago

I'm not familiar enough with this library to want to make a pull request (and I know this thread is old), but this works for me

class SwitchPro(Gamepad.Gamepad):
    fullName = "Nintendo Switch Pro Controller"

    def __init__(self, joystickNumber=0):
        Gamepad.Gamepad.__init__(self, joystickNumber)
        self.axisNames = {
            # Joysticks
            1: "LSV",  # Left Stick Vertical
            0: "LSH",  # eft Stick Horizontal
            3: "RSV",  # Right Stick Vertical
            2: "RSH",  # Right Stick Horizontal
            # D pad
            5: "DV",  # D-Pad Vertical
            4: "DH",  # D-Pad Horizontal
        }

        self.buttonNames = {
            # faces
            0: "B",
            1: "A",
            2: "X",
            3: "Y",
            # menuing
            10: "Plus",
            9: "Minus",
            # joysticks
            12: "Left Stick Button",
            13: "Right Stick Button",
            # special
            11: "Home",
            4: "Screenshot",
            # bumpers / triggers
            5: "LB",
            6: "RB",
            7: "LT",
            8: "RT",
        }

        self._setupReverseMaps()