Sign in to follow this  
MrPlosion1243

Multiple Controllers with DirectInput

Recommended Posts

MrPlosion1243    142
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 [url="http://www.amazon.com/PS2-USB-Dual-Controller-Adapter-Converter/dp/B000F6BGXY"]PlayStation to USB adapter[/url] and plugged it all in.

I'm using [url="http://slimdx.org/"]SlimDX[/url]'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:
[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();
[/CODE]

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/ Edited by MrPlosion1243

Share this post


Link to post
Share on other sites
6677    1054
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
[CODE]
int index = 0;

[/CODE]


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. Edited by 6677

Share this post


Link to post
Share on other sites
MrPlosion1243    142
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 [url="http://i.imgur.com/jz3cO.png"]like so[/url] 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.

Share this post


Link to post
Share on other sites
6677    1054
also you you could use XNA's input libraries although that would mean including the XNA redistributable with your program so maybe not.

Share this post


Link to post
Share on other sites
MrPlosion1243    142
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this