到目前为止的代码:
Device gamepad;
public bool initializeGamePad()
{
foreach ( DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly) )
{
gamepad = new Device(di.InstanceGuid);
break;
}
if (gamepad==null)//no gamepads detected
return false;
else
{
configureGamePad();
return true;
}
}
public void configureGamePad()
{
//Set axis ranges
foreach (DeviceObjectInstance doi in gamepad.Objects)
{
if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
{
gamepad.Properties.SetRange(ParameterHow.ById, doi.ObjectId, new InputRange(-5000, 5000));
}
}
//Set joystick axis mode absolute
gamepad.Properties.AxisModeAbsolute = true;
//set cooperative level.
gamepad.SetCooperativeLevel(new Form1(), CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
//Acquire devices for capturing
gamepad.Acquire();
UpdateJoystick();
}
private void UpdateJoystick()
{
string info = "Joystick: ";
//Get Mouse State
JoystickState state = gamepad.CurrentJoystickState;
//Capture Position
info += "X:" + state.X + " ";
info += "Y:" + state.Y + " ";
info += "Z:" + state.Z + " ";
info += "ARx:" + state. + "\n";
//Capture Buttons
byte[] buttons = state.GetButtons();
for (int i = 0; i < buttons.Length; i++)
{
if (buttons[i] != 0)
{
info += "Button:" + i + " ";
}
}
MessageBox.Show(info);
}
问题是信息字符串仅包含 state.X/Y/Z 的值 0,而与按钮无关。
我需要这样的东西: button_down 和 button_release 以便同时按下 2 个或更多按钮。和轴位置。
此外,我只使用 DirectX SKD 没有 SlimDX 或其他任何东西。