到目前爲止的代碼:檢測手柄輸入
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 –