How do I merge the inputs from two game controllers?

39 Views Asked by At

I'm working on a motion control program that turns joy-con motions into virtual Xbox 360 button presses. It works using two joy-cons as a pair. But my difficulty is in adding a second pair (four joy-cons total). The second pair creates a second virtual Xbox 360 controller. But I actually want to use the motions of all four joy-cons for the first virtual Xbox controller.

Here's what the motion function looks like.

        void DetectShake() {
            float accelShakeSensitivityX;
            Button simulatedButtonPress, simulatedButtonRelease;

            // Configure different pairs based on PadId and whether it's a left or right Joy-Con
            if (this.PadId == 0 || this.PadId == 1) { // Pair 1
                if (this.isLeft) {
                    accelShakeSensitivityX = 20.0f;
                    simulatedButtonPress = Button.SHOULDER2_1; 
                    simulatedButtonRelease = Button.SHOULDER2_1; 
                } else {
                    accelShakeSensitivityX = 20.0f; 
                    simulatedButtonPress = Button.X; 
                    simulatedButtonRelease = Button.X; 
                }
            } else { // Pair 2
                if (this.isLeft) {
                    accelShakeSensitivityX = 20.0f; ; 
                    simulatedButtonPress = Button.B; 
                    simulatedButtonRelease = Button.B; 
                } else {
                    accelShakeSensitivityX = 20.0f; ; 
                    simulatedButtonPress = Button.A; 
                    simulatedButtonRelease = Button.A; 
                }
            }

So PadId 0 and PadId 1 form pair one, while any other PadId is used for pair two. This allows me to implement different buttons for each of the four joy-cons. But is there a way to fool my program into perceiving data that comes from those other PadIds is actually from PadId 0 or 1? That way I might still be able to map each joy-con separately, but it should relay the button press to the first virtual Xbox 360 controller instead of the second.

I did first try to stop the creation of a second virtual Xbox 360 controller, so that all four joy-cons control one virtual Xbox controller. But this opened up a big can of worms because inputs of both pairs constantly competed with each other, rapidly switching between states. And trying to fix that seemed a lot harder than focusing solely on getting the motion inputs from one pair to the other.

P.S. I am a total beginner working on a rather advanced implementation, so I might simply be in over my head. Feel free to disregard this if my question is dumb.

0

There are 0 best solutions below