0
\$\begingroup\$

I can get a list of the joysticks connected to my PC. But now I want to send effects for example to send a command that will make a button click for example the triangle button or the square button.

But I'm not sure how to continue with the effects and how to send the commands to the buttons.

I'm stuck in the HandleJoystick method.

namespace Ps4_Controller
{
    public partial class Form1 : Form
    {
        DirectInput input = new DirectInput();
        Joystick stick;

        public Form1()
        {
            InitializeComponent();

            stick = ListJoysticks()[0];
        }

        private Joystick[] ListJoysticks()
        {
            List<Joystick> sticks = new List<Joystick>();

            foreach (DeviceInstance device in input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
            {
                Joystick stick = new Joystick(input, device.InstanceGuid);
                stick.Acquire();

                foreach (DeviceObjectInstance deviceObject in stick.GetObjects(DeviceObjectTypeFlags.Axis))
                {
                    stick.GetObjectPropertiesById(deviceObject.ObjectId).Range = new InputRange(-100, 100);
                }
                sticks.Add(stick);
            }
            return sticks.ToArray();
        }

        private void HandleJoystick()
        {
            Joystick stick = ListJoysticks()[0];
            int[] axis = new int[0];

            foreach (DeviceObjectInstance doi in stick.GetObjects())
            {
                axis = new int[axis.Length + 1];
                axis[axis.Length - 1] = doi.Offset;
            }

            EffectParameters ep = new EffectParameters();
            DeviceInstance stick1 = new DeviceInstance();


            Effect effect = new Effect(stick.);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
}
\$\endgroup\$
2
  • 4
    \$\begingroup\$ I think you might be confused. Generally, a joystick is an input device - your program responds to it & takes whatever action you deem/program to be appropriate. You do not send commands to the buttons. \$\endgroup\$
    – Pikalek
    Commented Dec 9, 2016 at 16:30
  • \$\begingroup\$ +1 Pikalek , there is "no feature yet" to allow developer to send special command to button at the joystick \$\endgroup\$ Commented Dec 9, 2016 at 16:43

1 Answer 1

1
\$\begingroup\$

I'm assuming you are looking to receive input from the controller, and not actually trying to send data to the controller.

First, an Effect in this context is referring to a force-feedback effect (IE. rumble).

If you are looking to query the Joystick object for input, you must first set the object to used buffered data by setting it's BufferSize property.

Joystick stick; //Use whatever code you desire for selection of proper Joystick object
stick.Properties.BufferSize = 128;
stick.Acquire();

Then you can poll the joystick for input data:

while (true)
{
    stick.Poll();
    var datas = stick.GetBufferedData();
    foreach (var state in datas)
    Console.WriteLine(state);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .