Multiple Controllers with DirectInput

Started by
6 comments, last by MrPlosion1243 11 years, 9 months ago
So I was going through my old stuff and found two PlayStation controllers. I thought It would be cool to use them in the game I'm developing as a self thing, I know other people don't have old PlayStation controllers but I do. So I bought a PlayStation to USB adapter and plugged it all in.

I'm using SlimDX's wrapper for DirectInput but only one port seems to work out of two that you can see from the image. It's really strange because DirectInput.GetDevices() returns a list of the available game pad devices and in that list is two devices which is exactly what I would expect. When I index the first device in the list sure enough I get the first port. However when I index the second device in the list I get the first port again. I don't know if this is a manufacturing problem or if it's with SlimDX. I do know it's not a problem with the controllers as they both work fine when plugged into the PlayStation.

So how come I always get the first port regardless of which object I pick from the DirectInput.GetDevices() list? I am completely stumped on why this would be happening and was hoping I could get some feed back on this issue.

Code:

int index = 1; //for some reason it always gets the first port.
DirectInput directInput = new DirectInput();
Guid controller = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AllDevices)[index].ProductGuid;
gamePad = new Joystick(directInput, controller);
gamePad.SetCooperativeLevel(gameRef.Window.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
gamePad.Properties.AxisMode = DeviceAxisMode.Absolute;
gamePad.Properties.SetRange(-5000, 5000);
gamePad.Acquire();


EDIT:

The game runs in XNA and here's the download to it if you're interested of course you'll need the same adapter though.

http://www.fileswap.com/dl/AaP3FWolEk/
Advertisement
Most indexes are 0 based, ie controller one will be labelled 0 and controller 2 will be listed 1, 3 would be listed 2 and so on. Have you considered that the controller you have working (index 1) might be the second player and when you set index to 2 because that is outside the range your getting player 2 again?

try

int index = 0;




If its not that then it might be the adaptor. I've not used directx directly, only through XNA, so something might stand out to someone else as being wrong. Gamepads are handled differently under XNA.
Yeah, I realize that indexes start at 0. I just had it set at 1 to kinda show off that even at 1 it still gets the first port instead of the expected 2nd port. So yes setting the index to 0 will get the first port but so will setting it to 1 which is the whole point of this thread.

Another thing worth noting that I forgot to say is that when I go into the Control Panel>>Hardware and Sound>>Game Controllers (on vista) I receive the same kinda thing. A list with two controllers like so and I can access both controllers perfectly with each port working fine. So I don't think it has to do with the adapter.

I just don't know.
Just an idea, but have you tried using the raw input API?
No but I suppose I'll have to use it if it can support game pads.
also you you could use XNA's input libraries although that would mean including the XNA redistributable with your program so maybe not.
The game is actually running in XNA and no I can't use it's Input libraries because it only works with the XBox 360 controller and not some PlayStation adapter.
Okay I've figured it out!! It's funny that I'm answering my own thread and I probably look like an idiot but oh well. I just simply used the InstanceGuid instead of the ProductGuid. This is because the ProductGuid is set by the manufacturer so both controllers had the same guid and I guess it didn't know which one to use so it just used the first one out of the two.

This topic is closed to new replies.

Advertisement