user23066555
user23066555

Reputation:

Trouble detecting PlayStation controller using SharpDX in C#

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)

Upvotes: 2

Views: 444

Answers (1)

krystian_sputo
krystian_sputo

Reputation: 61

DeviceType.FirstPerson worked in my case for Playstation 4 controller

directInput = new DirectInput();
var joystickGuid = Guid.Empty;

foreach (var deviceInstance in directInput.GetDevices(DeviceType.FirstPerson, DeviceEnumerationFlags.AllDevices))
{
    joystickGuid = deviceInstance.InstanceGuid;
}

Upvotes: 0

Related Questions