当前位置: 首页>>代码示例>>C#>>正文


C# Joystick.GetEffects方法代码示例

本文整理汇总了C#中Joystick.GetEffects方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.GetEffects方法的具体用法?C# Joystick.GetEffects怎么用?C# Joystick.GetEffects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Joystick的用法示例。


在下文中一共展示了Joystick.GetEffects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainForJoystick

        static void MainForJoystick()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                Console.ReadKey();
                Environment.Exit(1);
            }

            // Instantiate the joystick
            var joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();

            // Poll events from joystick
            while (true)
            {
                joystick.Poll();
                var datas = joystick.GetBufferedData();
                foreach (var state in datas)
                    Console.WriteLine(state);
            }
        }
开发者ID:numo16,项目名称:SharpDX,代码行数:49,代码来源:Program.cs

示例2: Manual

        public Manual()
        {
            // Initialize DirectInput

            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                        DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            if (joystickGuid != Guid.Empty)
            {
                //fix running code without controller
                //Environment.Exit(1);

                // Instantiate the joystick
                joystick = new Joystick(directInput, joystickGuid);

                Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                // Query all suported ForceFeedback effects
                var allEffects = joystick.GetEffects();
                foreach (var effectInfo in allEffects)
                    Console.WriteLine("Effect available {0}", effectInfo.Name);

                // Set BufferSize in order to use buffered data.
                joystick.Properties.BufferSize = 128;

                // Acquire the joystick
                joystick.Acquire();
                ControllerOn = true;
            }
        }
开发者ID:LTUBlueDevil,项目名称:IGVC-2016,代码行数:43,代码来源:Manual.cs

示例3: FindGamepad

        public static Joystick FindGamepad()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                        DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            GamePadConnected = true;
            if (joystickGuid == Guid.Empty)
            {
                MainWindow.GPID = "No Gamepad found.";
                GamePadConnected = false;
                //Environment.Exit(1);
            }

            // Instantiate the joystick
            var joystick = new Joystick(directInput, joystickGuid);

            MainWindow.GPID = "Gamepad GUID: " + joystickGuid;

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();

            // Poll events from joystick
            //  while (true)
            // {
            //    joystick.Poll();
            //    var datas = joystick.GetBufferedData();
            //  foreach (var state in datas)
            //    Console.WriteLine(state);
            //}

            return joystick;
        }
开发者ID:Thomas-Brothers-Workshop,项目名称:TCPClient,代码行数:54,代码来源:MainWindow.xaml.cs

示例4: ShowDeviceInfo

 void ShowDeviceInfo(Joystick device)
 {
     if (device == null)
     {
         // clean everything here.
         SetValue(DeviceProductNameTextBox, "");
         SetValue(DeviceProductGuidTextBox, "");
         SetValue(DeviceInstanceGuidTextBox, "");
         DiCapFfStateTextBox.Text = string.Empty;
         DiCapAxesTextBox.Text = string.Empty;
         DiCapButtonsTextBox.Text = string.Empty;
         DiCapDPadsTextBox.Text = string.Empty;
         DiEffectsTable.Rows.Clear();
         return;
     }
     lock (MainForm.XInputLock)
     {
         var isLoaded = XInput.IsLoaded;
         if (isLoaded) XInput.FreeLibrary();
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
         effects = new List<EffectInfo>();
         try
         {
             device.Acquire();
             var forceFeedback = device.Capabilities.Flags.HasFlag(DeviceFlags.ForceFeedback);
             forceFeedbackState = forceFeedback ? "YES" : "NO";
             effects = device.GetEffects(EffectType.All);
         }
         catch (Exception)
         {
             forceFeedbackState = "ERROR";
         }
         DiEffectsTable.Rows.Clear();
         foreach (var eff in effects)
         {
             DiEffectsTable.Rows.Add(new object[]{
                         eff.Name,
                         ((EffectParameterFlags)eff.StaticParameters).ToString(),
                         ((EffectParameterFlags)eff.DynamicParameters).ToString()
                     });
         }
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
         if (isLoaded)
         {
             Exception error;
             XInput.ReLoadLibrary(XInput.LibraryName, out error);
         }
     }
     DiCapFfStateTextBox.Text = forceFeedbackState;
     DiCapButtonsTextBox.Text = device.Capabilities.ButtonCount.ToString();
     DiCapDPadsTextBox.Text = device.Capabilities.PovCount.ToString();
     var objects = device.GetObjects(DeviceObjectTypeFlags.All).OrderBy(x => x.Offset).ToArray();
     DiObjectsTable.Rows.Clear();
     var og = typeof(SharpDX.DirectInput.ObjectGuid);
     var guidFileds = og.GetFields().Where(x => x.FieldType == typeof(Guid));
     List<Guid> guids = guidFileds.Select(x => (Guid)x.GetValue(og)).ToList();
     List<string> names = guidFileds.Select(x => x.Name).ToList();
     foreach (var o in objects)
     {
         DiObjectsTable.Rows.Add(new object[]{
                         o.Offset,
                         o.ObjectId.InstanceNumber,
                         o.Usage,
                         o.Name,
                         o.Aspect,
                         guids.Contains(o.ObjectType) ?  names[guids.IndexOf(o.ObjectType)] : o.ObjectType.ToString(),
                         o.ObjectId.Flags,
                     });
     }
     var actuators = objects.Where(x => x.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator));
     ActuatorsTextBox.Text = actuators.Count().ToString();
     var di = device.Information;
     var slidersCount = objects.Where(x => x.ObjectType.Equals(SharpDX.DirectInput.ObjectGuid.Slider)).Count();
     DiCapAxesTextBox.Text = (device.Capabilities.AxeCount - slidersCount).ToString();
     SlidersTextBox.Text = slidersCount.ToString();
     // Update PID and VID always so they wont be overwritten by load settings.
     short vid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 0);
     short pid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 2);
     SetValue(DeviceVidTextBox, "0x{0}", vid.ToString("X4"));
     SetValue(DevicePidTextBox, "0x{0}", pid.ToString("X4"));
     SetValue(DeviceProductNameTextBox, di.ProductName);
     SetValue(DeviceProductGuidTextBox, di.ProductGuid.ToString());
     SetValue(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString());
     SetValue(DeviceTypeTextBox, di.Type.ToString());
 }
开发者ID:suvjunmd,项目名称:x360ce,代码行数:87,代码来源:DirectInputControl.cs

示例5: initialize_joystick

        private void initialize_joystick()
        {
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                throw new Exception("controllerNotFound");
            }
            // Instantiate the joystick
            joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();
        }
开发者ID:RASC-AL,项目名称:Interface,代码行数:37,代码来源:Interface.cs

示例6: ShowDeviceInfo

 void ShowDeviceInfo(Joystick device, DeviceInfo dInfo)
 {
     if (device == null)
     {
         // clean everything here.
         AppHelper.SetText(DeviceProductNameTextBox, "");
         AppHelper.SetText(DeviceVendorNameTextBox, "");
         AppHelper.SetText(DeviceProductGuidTextBox, "");
         AppHelper.SetText(DeviceInstanceGuidTextBox, "");
         AppHelper.SetText(DiCapFfStateTextBox, "");
         AppHelper.SetText(DiCapAxesTextBox, "");
         AppHelper.SetText(DiCapButtonsTextBox, "");
         AppHelper.SetText(DiCapDPadsTextBox, "");
         if (DiEffectsTable.Rows.Count > 0) DiEffectsTable.Rows.Clear();
         return;
     }
     lock (MainForm.XInputLock)
     {
         var isLoaded = XInput.IsLoaded;
         if (isLoaded) XInput.FreeLibrary();
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
         effects = new List<EffectInfo>();
         try
         {
             device.Acquire();
             var forceFeedback = device.Capabilities.Flags.HasFlag(DeviceFlags.ForceFeedback);
             forceFeedbackState = forceFeedback ? "YES" : "NO";
             effects = device.GetEffects(EffectType.All);
         }
         catch (Exception)
         {
             forceFeedbackState = "ERROR";
         }
         DiEffectsTable.Rows.Clear();
         foreach (var eff in effects)
         {
             DiEffectsTable.Rows.Add(new object[]{
                         eff.Name,
                         ((EffectParameterFlags)eff.StaticParameters).ToString(),
                         ((EffectParameterFlags)eff.DynamicParameters).ToString()
                     });
         }
         device.Unacquire();
         device.SetCooperativeLevel(MainForm.Current, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
         if (isLoaded)
         {
             Exception error;
             XInput.ReLoadLibrary(XInput.LibraryName, out error);
         }
     }
     AppHelper.SetText(DiCapFfStateTextBox, forceFeedbackState);
     AppHelper.SetText(DiCapButtonsTextBox, device.Capabilities.ButtonCount.ToString());
     AppHelper.SetText(DiCapDPadsTextBox, device.Capabilities.PovCount.ToString());
     var objects = AppHelper.GetDeviceObjects(device);
     DiObjectsDataGridView.DataSource = objects;
     var actuators = objects.Where(x => x.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator));
     AppHelper.SetText(ActuatorsTextBox, actuators.Count().ToString());
     var di = device.Information;
     var slidersCount = objects.Where(x => x.GuidValue.Equals(SharpDX.DirectInput.ObjectGuid.Slider)).Count();
     AppHelper.SetText(DiCapAxesTextBox, (device.Capabilities.AxeCount - slidersCount).ToString());
     AppHelper.SetText(SlidersTextBox, slidersCount.ToString());
     // Update PID and VID always so they wont be overwritten by load settings.
     short vid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 0);
     short pid = BitConverter.ToInt16(di.ProductGuid.ToByteArray(), 2);
     AppHelper.SetText(DeviceVidTextBox, "0x{0:X4}", vid);
     AppHelper.SetText(DevicePidTextBox, "0x{0:X4}", pid);
     AppHelper.SetText(DeviceProductNameTextBox, di.ProductName);
     AppHelper.SetText(DeviceVendorNameTextBox, dInfo == null ? "" : dInfo.Manufacturer);
     AppHelper.SetText(DeviceRevTextBox, "0x{0:X4}", dInfo == null ? 0 : dInfo.Revision);
     AppHelper.SetText(DeviceProductGuidTextBox, di.ProductGuid.ToString());
     AppHelper.SetText(DeviceInstanceGuidTextBox, di.InstanceGuid.ToString());
     AppHelper.SetText(DeviceTypeTextBox, di.Type.ToString());
 }
开发者ID:cagrawal21,项目名称:x360ce,代码行数:74,代码来源:DirectInputControl.cs

示例7: Initialize

        public bool Initialize(string instanceName)
        {
            bool bFoundDevice = false;

            // Initialize DirectInput
            DirectInput directInput = new DirectInput();

            // Find a Joystick Guid
            Guid joystickGuid = Guid.Empty;

            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            {
                if (deviceInstance.InstanceName == instanceName)
                {
                    //found the device
                    joystickGuid = deviceInstance.InstanceGuid;
                }
            }

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
            {
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
                {
                    if (deviceInstance.InstanceName == instanceName)
                    {
                        joystickGuid = deviceInstance.InstanceGuid;
                    }
                }
            }

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found: " + instanceName);
            }
            else
            {
                bFoundDevice = true;

                // Instantiate the joystick
                joystick = new Joystick(directInput, joystickGuid);

                Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                // Query all suported ForceFeedback effects
                var allEffects = joystick.GetEffects();
                foreach (var effectInfo in allEffects)
                {
                    Console.WriteLine("Effect available {0}", effectInfo.Name);
                }

                // Set BufferSize in order to use buffered data.
                joystick.Properties.BufferSize = 128;

                // Acquire the joystick
                joystick.Acquire();
            }

            return bFoundDevice;
        }
开发者ID:NaterTots,项目名称:PaintWithMe,代码行数:61,代码来源:JoystickDevice.cs

示例8: _Joystic

        public static void _Joystic()
        {

            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;


            foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad,
                    DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
                _is_joysticConnect = true;

            }
            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                        DeviceEnumerationFlags.AllDevices))
            {
                joystickGuid = deviceInstance.InstanceGuid;
                _is_joysticConnect = true;
            }
            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                _is_joysticConnect = false;
            }

            if (_is_joysticConnect)
            {
                var joystick = new Joystick(directInput, joystickGuid);

                Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

                // Query all suported ForceFeedback effects
                var allEffects = joystick.GetEffects();
                foreach (var effectInfo in allEffects)
                    Console.WriteLine("Effect available {0}", effectInfo.Name);

                // Set BufferSize in order to use buffered data.
                joystick.Properties.BufferSize = 128;

                // Acquire the joystick
                joystick.Acquire();

                // Poll events from joystick
                var joystickState = new JoystickState();
                bool work;
                while (_continue )
                {
                    work = false;
                    joystick.Poll();
                    var data = joystick.GetBufferedData();
                    foreach (var state in data)
                    {

                        if (state.Offset == JoystickOffset.X)
                        {
                            yaw_curr = ((32767 - state.Value) / 4096);
                            if (Math.Abs(yaw_curr - yaw_prev) >3 )
                            {
                                string mes = Convert.ToString(yaw_curr);
                                while (mes.Length < 5)
                                {
                                    mes = ' ' + mes;
                                }
                                _serialPort.WriteLine('y' + mes);
                                yaw_prev = yaw_curr;

                            }
                            work = true;
                        }
                        if (state.Offset == JoystickOffset.Z)
                        {
                            pitch_curr = ((32767 - state.Value) / 20) + pitch0;
                            if(Math.Abs(pitch_curr - pitch_prev)>100)
                            {
                                string mes = Convert.ToString(pitch_curr);
                                while (mes.Length < 5)
                                {
                                    mes = ' ' + mes;
                                }
                                _serialPort.WriteLine('p'+mes);
                                pitch_prev = pitch_curr;
                                
                            }
                            work = true;
                        }
                        if (state.Offset == JoystickOffset.RotationZ)
                        {
                            roll_curr = ((state.Value - 32767) / 20) + roll0;
                            if (Math.Abs(roll_curr - roll_prev) > 100)
                            {
                                string mes = Convert.ToString(roll_curr);
                                while (mes.Length < 5)
                                {
                                    mes = ' ' + mes;
//.........这里部分代码省略.........
开发者ID:vetal1808,项目名称:val_plot,代码行数:101,代码来源:Form1.cs

示例9: Main

        static void Main(string[] args)
        {
            if (client == null)
            {
                // create client instance
                client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));

                string clientId = Guid.NewGuid().ToString();
                client.Connect(clientId, "guest", "guest");

                SubscribeMessage();
            }
            // Initialize DirectInput

            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick,
                        DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                Console.ReadKey();
                Environment.Exit(1);
            }

            // Instantiate the joystick
            var joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();
            const int stop = 32511;
            // Poll events from joystick
            while (true)
            {
                joystick.Poll();
                var datas = joystick.GetBufferedData();
                foreach (var state in datas)
                {
                    if (state.Offset.ToString() == "X" && state.Value > stop)
                    {
                        MoveRobot("MOVE", "R");
                        Console.WriteLine("Kanan");
                    }
                    else if(state.Offset.ToString() == "X" && state.Value < stop)
                    {
                        MoveRobot("MOVE", "L");

                        Console.WriteLine("Kiri");
                    }
                    else if (state.Offset.ToString() == "Y" && state.Value < stop)
                    {
                        MoveRobot("MOVE", "F");

                        Console.WriteLine("Maju");
                    }
                    else if (state.Offset.ToString() == "Y" && state.Value > stop)
                    {
                        MoveRobot("MOVE", "B");

                        Console.WriteLine("Mundur");
                    }
                    else
                    {
                        MoveRobot("MOVE", "S");

                        Console.WriteLine("Stop");
                    }

                }

            }
        }
开发者ID:Gravicode,项目名称:RCGadgeteer,代码行数:94,代码来源:Program.cs

示例10: MainForJoystick

        static void MainForJoystick()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            // If Gamepad not found, look for a Joystick
            if (joystickGuid == Guid.Empty)
                foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
                    joystickGuid = deviceInstance.InstanceGuid;

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                Console.ReadKey();
                Environment.Exit(1);
            }
            // Instantiate the joystick
            var joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();
            string s = "there is a cat";
            string[] words = s.Split(' ');
            foreach (string word in words)
            {
                Console.WriteLine(word);
            }
            // Poll events from joystick
            var originX = 0;
            var originY = 0;
            var lastStateX = -1;
            var lastStateY = -1;
            var startFlag = false;
            while (true)
            {
                joystick.Poll();
                var datas = joystick.GetBufferedData();
                double theta = 0.0;
                double radius = 0.0;

                foreach (var state in datas)
                {
                    if (state.Sequence == 1)
                    {
                        s = (state.Offset).ToString();
                        if (s == "X")
                            originX = state.Value;
                        else if (s == "Y")
                            originY = state.Value;
                    }
                    s = (state.Offset).ToString();
                    if (s == "X")
                        lastStateX = state.Value;
                    else if (s == "Y")
                        lastStateY = state.Value;
                    startFlag = true;
                }
                if (startFlag && datas.Length == 0 && lastStateX != -1 && lastStateY != -1)
                {
                    var slope = 0.0;
                    if ((lastStateX - originX) == 0)
                        slope = Math.PI / 2;
                    else
                        slope = (lastStateY - originY) / (lastStateX - originX);
                    theta = Math.Atan(slope);
                    radius = Math.Sqrt(Math.Pow(originX - lastStateX, 2) + Math.Pow(originY - lastStateY, 2));
                    originX = lastStateX;
                    originY = lastStateY;
                    Console.WriteLine(theta);
                    Console.WriteLine(radius);
                    startFlag = false;
                }
            }
        }
开发者ID:RASC-AL,项目名称:Interface,代码行数:91,代码来源:Program.cs

示例11: pollJoystick

        private void pollJoystick(Guid joystickGuid)
        {
            Joystick joystick;

            // Instantiate the joystick
            joystick = new Joystick(directInput, joystickGuid);
            joystick.Properties.BufferSize = 128;

            Console.WriteLine("Joystick {0}", joystick.Properties.ProductName.ToString());
            Console.WriteLine("GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            // TODO - maybe look into vibration effects on gamepads?
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
            {
                Console.WriteLine("Effect available {0}", effectInfo.Name);
            }

            // Acquire the joystick
            joystick.Acquire();

            // Poll events from joystick
            while (true)
            {
                joystick.Poll();
                var data = joystick.GetBufferedData();
                foreach (var state in data)
                {
                    //Null characters in the device name clogs up the write buffer when not run as a Console app. Replace all \0 with empty string to fix this.
                    Console.WriteLine("{0} - {1} - {2}", joystick.Properties.InstanceName.Replace("\0", ""), state.Offset, state.Value);

                    if (state.Offset.ToString().StartsWith("Button"))
                    {

                        buttonPressed(state.Offset, state.Value);
                        Console.WriteLine("Button {0} state changed to {1}", state.Offset, state.Value);

                    }
                    else if (state.Offset.ToString().StartsWith("Point"))
                    {

                        // POV controller
                        povChanged(state.Offset, state.Value);

                    }
                    else
                    {

                        //is an axis
                        int range = 32767; // this is for main joysticks. Might have to change if there are issues
                        axisMoved(state.Offset, state.Value, range);

                    }

                }
            }
        }
开发者ID:LiveFlightApp,项目名称:Connect-Windows,代码行数:58,代码来源:JoystickHelper.cs

示例12: joystickManagerThreadStart

        private void joystickManagerThreadStart()
        {
            // Initialize DirectInput
            var directInput = new DirectInput();

            // Find a Joystick Guid
            var joystickGuid = Guid.Empty;

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

            foreach (var deviceInstance in directInput.GetDevices())
            {
                if (deviceInstance.InstanceName.Contains("X52 Pro"))
                {
                    Console.WriteLine(deviceInstance.InstanceName+", "+deviceInstance.InstanceGuid);
                    joystickGuid = deviceInstance.InstanceGuid;
                }
            }

            // If Joystick not found, throws an error
            if (joystickGuid == Guid.Empty)
            {
                Console.WriteLine("No joystick/Gamepad found.");
                Console.ReadKey();
                Environment.Exit(1);
            }
            // Instantiate the joystick
            joystick = new Joystick(directInput, joystickGuid);

            Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid);

            // Query all suported ForceFeedback effects
            var allEffects = joystick.GetEffects();
            foreach (var effectInfo in allEffects)
                Console.WriteLine("Effect available {0}", effectInfo.Name);

            // Set BufferSize in order to use buffered data.
            joystick.Properties.BufferSize = 128;

            // Acquire the joystick
            joystick.Acquire();
            // Poll events from joystick
            while (true)
            {
                joystick.Poll();
                var datas = joystick.GetBufferedData();
                foreach (var state in datas)
                {
                    if (state.Offset == JoystickOffset.Y)
                    {
                        Y_Axis = (state.Value - (Y_MAX_VAL / 2.0)) / (Y_MAX_VAL / 2.0);
                        if (Math.Abs(Y_Axis) <= 0.025)
                            Y_Axis = 0;
                        if (Y_INVERT)
                            Y_Axis *= -1;
                    }

                    if (state.Offset == JoystickOffset.X)
                    {
                        X_Axis = (state.Value - (X_MAX_VAL / 2.0)) / (X_MAX_VAL / 2.0);
                        if (Math.Abs(X_Axis) <= DEAD_ZONE)
                            X_Axis = 0;
                        if (X_INVERT)
                            X_Axis *= -1;
                    }

                    if(state.Offset == JoystickOffset.Z)
                    {
                        throttle = (state.Value) / ((double)X_MAX_VAL);
                        if (THROTTLE_INVERT)
                            throttle = (1 - throttle);
                    }

                    if(state.Offset == JoystickOffset.Buttons0)
                    {
                        if (state.Value == 128)
                            fire = true;
                        else
                            fire = false;
                    }
                }
            }
        }
开发者ID:kdolan,项目名称:Retaliator,代码行数:85,代码来源:frm_Primary.cs


注:本文中的Joystick.GetEffects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。