我正在使用Microsoft DirectX来访问我的游戏垫。这是一个像这样的usb游戏板:
我可以知道按下按钮的时间以及轴的模拟值.
问题是,如果有一种方法可以知道什么时候按下模拟按钮(红灯打开)。
这有可能吗?多么?
发布于 2013-04-24 05:11:21
我会为您的项目推荐SlimDX或SharpDX。它们支持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;
}
https://stackoverflow.com/questions/16192750
复制