코드 탐지 :게임 패드 입력을 지금까지
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 두 개 이상의 동시 버튼을 누를 수 있습니다. 그리고 축 위치.
또한 DirectX SKD를 사용하지 않고 SlimDX 또는 anyting만을 사용합니다.
일반적으로 게임 패드 입력은 게임용입니다. XNA를 통해서만 게임 패드를 사용했습니다. 사용중인 게임 패드 유형을 지정할 수 있습니까? Xbox 컨트롤러, 비행 스틱, 일반 D 패드/아날로그/4Button/트리거? –
무선 천재 게임 패드를 사용하고 있습니다 http://s1.emagst.ro/products/24/23618/images/img50860_02092009105416_350x350c_71dt.jpg –