Reputation: 79
i'm trying to use a ps3 controller for a game i'm creating. I downloaded the sharpDX.DirectInput extension into my visual studio XNA solution, and used the seemingly simple code from Valdemar's answer in Taking input from a joystick with C# .NET. I already narrowed the problem down to the fact that he cant find the guid of the controller, nor the guid of other USB connected devices such as a keyboard. It does works for the integrated keyboard of my laptop though. Here is my code:
directInput = new DirectInput();
// Find a Joystick Guid
foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
guid = deviceInstance.InstanceGuid;
//create joystick
if (guid!=Guid.Empty)
controller = new Joystick(directInput, guid);
The problem is that controller remains null, which means that the guid remains empty, which means that the GetDevices method doesn't find a gamepad. Which is strange because the controller is perfectly working in windows 7 and visible in device manager as HID and as Microsoft common controller for windows class.
btw, I got the same problem using Microsoft.DirectX.directInput.
Thanks for reading :)
Upvotes: 1
Views: 2357
Reputation: 13
One possible solution is to change the DeviceType.Gamepad to DeviceType.Joystick
Upvotes: 1
Reputation: 79
I still don't know why it didn't work. But I tried something better. with a tutorial on youtube i installed a driver which "converted" the DS3 controller into an xbox controller. In other words, windows now thinks there is a xbox controller connected.
Now I can use the GamePad class of the xna library which is designed for xbox 360 controllers.
http://steamcommunity.com/app/258970/discussions/0/613937306592303709/?l=dutch read the comments of this link for more updated drivers.
Upvotes: 0