需要一些帮助在C#中实现直接输入力反馈示例 [英] Need some help implementing a directinput force feedback example in C#

查看:73
本文介绍了需要一些帮助在C#中实现直接输入力反馈示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码。我要做的是创建一个exe,当运行时执行变量中定义的力反馈,然后退出。用户应该看不到GUI。作为第二步,我想启用exe的参数来控制持续时间,但这是另一个故事。



Code below. What I'm trying to do is create an exe that when run executes the force feedback defined in the variables and then exits. The user should see no GUI. As a second step I'd like to enable arguments for the exe to control the duration but that's another story.

DeviceList xDeviceList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly); 
        DeviceInstance someDeviceInstance; 
        foreach (DeviceInstance deviceInstance in xDeviceList) 
        { 
            someDeviceInstance = deviceInstance; 
            break; 
        } 

        Device someDevice = new Device(someDeviceInstance.InstanceGuid); 
        someDevice.SetCooperativeLevel(this.Handle, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background); 
        int[] axis = new int[0]; 
        foreach (DeviceObjectInstance doi in someDevice.Objects) 
        { 
            if((doi.Flags & (int)ObjectInstanceFlags.Actuator) != 0) 
            { 
                axis = new int[axis.Length + 1]; 
                axis[axis.Length - 1] = doi.Offset; 
            } 
        } 

        someDevice.Acquire(); 

        Effect effect = new Effect(); 
        effect.SetDirection(new int[axis.Length]); 
        effect.SetAxes(new int[axis.Length]); 
        effect.ConditionStruct = new Condition[axis.Length]; 

        effect.Flags = EffectFlags.Cartesian | EffectFlags.ObjectOffsets; 
        effect.Duration = int.MaxValue; 
        effect.SamplePeriod = 0; 
        effect.Gain = 10000; 
        effect.TriggerButton = (int)Microsoft.DirectX.DirectInput.Button.NoTrigger; 
        effect.TriggerRepeatInterval = 0; 
        effect.UsesEnvelope = false; 
        effect.EffectType = Microsoft.DirectX.DirectInput.EffectType.ConstantForce; 
        effect.StartDelay = 0; 
        effect.Constant = new Microsoft.DirectX.DirectInput.ConstantForce(); 
        effect.Constant.Magnitude = -5000; 
        EffectObject effectObject = null; 
        foreach (EffectInformation ei in someDevice.GetEffects(EffectType.ConstantForce)) 
        { 
            effectObject = new EffectObject(ei.EffectGuid, effect, someDevice); 
        } 

        effectObject.SetParameters(effect, EffectParameterFlags.Start ); 





我的尝试:



添加了DirectX引用,删除了GUI并将代码填入类中,但句柄部分会导致错误。



What I have tried:

Added the DirectX references, removed the GUI and stuffed the code in classes, but the handle part causes errors.

推荐答案

使用以下代码:直接输入力反馈示例 - Google搜索 [ ^ ]形成您的问题标题,我在第一个结果页面上找到以下内容:



* < a href =https://msdn.microsoft.com/en-us/library/windows/desktop/bb153254(v=vs.85).aspx>使用强制反馈(带有C#示例代码) [ ^ ]



* 托管DirectX中的强制反馈(此处代码项目) [ ^ ]



* c# - 从.net发送反馈/效果到操纵杆 - Stack Overflow [ ^ ]



*以及更多,更多......
Using the following: directinput force feedback example in C# - Google Search[^] form your question title, I found the following on the first results page:

* Using Force Feedback (with C# sample code)[^]

* Force Feedback in Managed DirectX (here on Code Project)[^]

* c# - Send feedback/effect to joystick from .net - Stack Overflow[^]

* and much, much, more...


这篇关于需要一些帮助在C#中实现直接输入力反馈示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆