• 大小: 168KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: directinput  手柄  

资源简介

基于 directinput 手柄操控、包含震动 源码

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectInput;

namespace DxJoystickCtrl
{
    /// 
    /// 手柄\摇杆信息获取于设置力反馈控制类
    /// 该类型由CSDN Icdbow 整理编写,如有不到之处欢迎发函指导 icdbow@tom.com
    /// 

    class JoystickControls
    {
        /// 
        /// 实例化
        /// 

        public JoystickControls(System.Windows.Forms.Control Parent)
        {
            joysticks = new List();
            forces = new Dictionaryject>[Manager.GetDevices(DeviceClass.GameControl EnumDevicesFlags.AttachedOnly).Count];

            foreach (DeviceInstance info in Manager.GetDevices(DeviceClass.GameControl EnumDevicesFlags.AttachedOnly))
            {
                Device myJoy = new Device(info.InstanceGuid);

                myJoy.SetCooperativeLevel(Parent CooperativeLevelFlags.Background | CooperativeLevelFlags.Exclusive);
                //Axis的绝对位置模式設定 
                myJoy.Properties.AxisModeAbsolute = true;
                myJoy.Properties.AutoCenter = false;
                myJoy.Acquire();

                int[] axis = null;
                foreach (DeviceobjectInstance doi in myJoy.objects)
                {
                    if ((doi.objectId & (int)DeviceobjectTypeFlags.Axis) != 0)
                    {
                        myJoy.Properties.SetRange(ParameterHow.ById doi.objectId new InputRange(-128 128));
                    }

                    int[] temp;

                    if ((doi.Flags & (int)objectInstanceFlags.Actuator) != 0)
                    {
                        if (axis != null)
                        {
                            temp = new int[axis.Length + 1];
                            axis.CopyTo(temp 0);
                            axis = temp;
                        }
                        else
                        {
                            axis = new int[1];
                        }
                        axis[axis.Length - 1] = doi.Offset;
                    }
                }

                //将Joystick的Device追加到Joystick列表
                joysticks.Add(myJoy);
                forces[joysticks.Count - 1] = new Dictionaryject>();
                try
                {
                    if (axis != null)
                    {
                        forces[joysticks.Count - 1].Add(ForceType.VeryBriefJolt InitializeForce(myJoy EffectType.ConstantForce axis 6000 EffectFlags.objectOffsets | EffectFlags.Spherical 150000));
                        forces[joysticks.Count - 1].Add(ForceType.BriefJolt InitializeForce(myJoy EffectType.ConstantForce axis 10000 EffectFlags.objectOffsets | EffectFlags.Spherical 250000));
                        forces[joysticks.Count - 1].Add(ForceType.LowRumble InitializeForce(myJoy EffectType.ConstantForce axis 2000 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     151552  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\bin\Debug\DxJoystickCtrl.exe

     文件      34304  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\bin\Debug\DxJoystickCtrl.pdb

     文件      11608  2011-09-01 22:06  DxJoystickCtrl\DxJoystickCtrl\bin\Debug\DxJoystickCtrl.vshost.exe

     文件        490  2009-08-31 00:40  DxJoystickCtrl\DxJoystickCtrl\bin\Debug\DxJoystickCtrl.vshost.exe.manifest

     文件       4408  2011-09-01 19:57  DxJoystickCtrl\DxJoystickCtrl\DxJoystickCtrl.csproj

     文件      67646  2011-09-01 19:57  DxJoystickCtrl\DxJoystickCtrl\Joy.ico

     文件       6460  2011-09-01 21:52  DxJoystickCtrl\DxJoystickCtrl\JoystickControls.cs

     文件       6982  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\Main_Form.cs

     文件       3145  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\Main_Form.Designer.cs

     文件     107589  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\Main_Form.resx

     文件       6322  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        838  2011-09-01 22:06  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DxJoystickCtrl.csproj.FileListAbsolute.txt

     文件     151552  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DxJoystickCtrl.exe

     文件      68212  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DxJoystickCtrl.Main_Form.resources

     文件      34304  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DxJoystickCtrl.pdb

     文件        180  2011-09-01 19:57  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\DxJoystickCtrl.Properties.Resources.resources

     文件       1030  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog

     文件        710  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog

     文件       8722  2011-08-31 11:48  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\ResolveAssemblyReference.cache

     文件        499  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Program.cs

     文件       1360  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Properties\AssemblyInfo.cs

     文件       2878  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Properties\Resources.Designer.cs

     文件       5612  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Properties\Resources.resx

     文件       1099  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Properties\Settings.Designer.cs

     文件        249  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\Properties\Settings.settings

     文件        884  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl.sln

    ..A..H.     19968  2011-09-01 19:59  DxJoystickCtrl\DxJoystickCtrl.suo

     文件      67646  2011-09-01 19:55  DxJoystickCtrl\Joy.ico

     目录          0  2011-08-31 11:45  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug\TempPE

     目录          0  2011-09-01 22:04  DxJoystickCtrl\DxJoystickCtrl\obj\x86\Debug

............此处省略10个文件信息

评论

共有 条评论