Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Want to set range for each joystick axis

$
0
0

Hi,

I am using joystick to move cameras and using below code to acquire joystick and setting range.

 DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
                int i = 0;
                bool found = false;
                // loop through the devices.
                foreach (DeviceInstance deviceInstance in gameControllerList)
                {
                    if (deviceInstance.InstanceName == name)
                    {
                        found = true;
                        // create a device from this controller so we can retrieve info.
                        joystickDevice = new Device(deviceInstance.InstanceGuid);

                        foreach (DeviceObjectInstance doi in joystickDevice.Objects)
                        {
                            if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                            {
                                joystickDevice.Properties.SetRange(ParameterHow.ById, doi.ObjectId, new InputRange(-9999, 9999));
                            }
                        }

                        joystickDevice.Properties.AxisModeAbsolute = true;

                        joystickDevice.SetCooperativeLevel(this.hWnd,
                            CooperativeLevelFlags.Background |
                            CooperativeLevelFlags.NonExclusive);
                        break;
                    }

                    i++;
                }

                if (!found)
                    return false;

                // Tell DirectX that this is a Joystick.
                joystickDevice.SetDataFormat(DeviceDataFormat.Joystick);

                // Finally, acquire the device.
                joystickDevice.Acquire();

                // How many axes?
                // Find the capabilities of the joystick
                Microsoft.DirectX.DirectInput.DeviceCaps cps = joystickDevice.Caps;
                Console.WriteLine("Joystick Axis: " + cps.NumberAxes);
                Console.WriteLine("Joystick Buttons: " + cps.NumberButtons);
            }

Now, I am setting range but I need to set different range to for diff Axis like I want to set -180,180 for X and Y axis and -9999,9999 for Z Axis. How can I achieve that.


Vipul Mistry Sr. Embedded Engineer www.eInfochips.com


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>