到目前为止的代码:检测手柄输入
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);
}
的问题是,信息字符串包含只值0的问候按钮state.X/Y/Z并没有什么。
我需要这样的:button_down & button_release为了得到2个或更多的同时按钮按下。和轴pozisions。
此外,我只使用DirectX SKD没有SlimDX或任何其他。
一般来说,游戏手柄输入是用于游戏。我只通过XNA使用了游戏手柄。你能指定你使用的是什么类型的游戏手柄吗? Xbox控制器,飞行操纵杆,通用D-Pad /模拟/ 4Button /触发器? –
我正在使用无线天才游戏手柄 http://s1.emagst.ro/products/24/23618/images/img50860_02092009105416_350x350c_71dt.jpg –