gpt4 book ai didi

c# - 操纵杆 + c# : Analog button

转载 作者:行者123 更新时间:2023-11-30 17:05:43 26 4
gpt4 key购买 nike

我正在使用 Microsoft DirectX 访问我的游戏 handle 。这是一个像这样的 USB 游戏 handle :

enter image description here

我可以知道何时按下按钮以及轴的模拟值...

问题是是否有办法知道何时按下模拟按钮(红灯亮起)。

这可能吗?如何?

最佳答案

我会推荐 SlimDXSharpDX为您的项目。它们支持 DirectX API,而且非常简单。

SlimDX:

using SlimDX.DirectInput;

创建一个新的 DirectInput 对象:

DirectInput input = new DirectInput();

然后是用于处理的 GameController 类:

public class GameController
{
private Joystick joystick;
private JoystickState state = new JoystickState();
}

然后像这样使用它:

public GameController(DirectInput directInput, Game game, int number)
{
// Search for Device
var devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
if (devices.Count == 0 || devices[number] == null)
{
// No Device
return;
}

// Create Gamepad
joystick = new Joystick(directInput, devices[number].InstanceGuid);
joystick.SetCooperativeLevel(game.Window.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);

// Set Axis Range for the Analog Sticks between -1000 and 1000
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
joystick.Acquire();
}

最后得到每个方法的状态:

public JoystickState GetState()
{
if (joystick.Acquire().IsFailure || joystick.Poll().IsFailure)
{
state = new JoystickState();
return state;
}

state = joystick.GetCurrentState();

return state;
}

关于c# - 操纵杆 + c# : Analog button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16192750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com