Problem:
I am working on a C# application to detect and handle input from a PlayStation controller using SharpDX and DirectInput. However, the code I have written doesn't seem to detect any controllers, even though I am sure the controller is connected and working perfectly (tested with DS4Windows).
Code:
var directInput = new DirectInput();
var devices = directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices);
foreach (var deviceInstance in devices)
{
MessageBox.Show("Device: " + deviceInstance.InstanceName);
}
var joystick = new Joystick(directInput, devices[0].InstanceGuid);
joystick.Acquire();
while (true)
{
joystick.Poll();
var data = joystick.GetBufferedData();
foreach (var state in data)
{
MessageBox.Show(state.Value.ToString());
}
}
Observations:
I have verified that the PlayStation controller is recognized by DS4Windows. The application doesn't detect any controllers when running the provided code.
What I've Tried:
Closing DS4Windows before running the application. Running the application with administrative privileges. Checking for exclusivity settings in DS4Windows. Updating SharpDX to the latest version.
Edit:
I'm open to use any method for reading inputs from a dualshock. (and it would be better if i also could send outputs too)
PlayStation controllers, especially DualShock 4, often have compatibility issues with DirectInput, as they are not natively supported by Windows in the same way Xbox controllers are. Here are some suggestions to troubleshoot and potentially resolve your issue:
Use RawInput Instead of DirectInput:
Check the DeviceType:
DeviceType.Gamepad
. PlayStation controllers are sometimes recognized asDeviceType.Joystick
instead ofDeviceType.Gamepad
. Try changing this in your code to see if it makes a difference.Use DS4Windows API or ViGEmBus:
Ensure Controller is in Exclusive Mode:
Check for Driver Issues:
Handling PlayStation controllers in a Windows environment can be tricky due to the lack of native support and often requires a workaround like emulating an Xbox controller.