1

これまでのコード:

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 のみが含まれ、ボタンに関しては何も含まれていないことです。

2 つ以上のボタンを同時に押すには、button_down と button_release のようなものが必要です。そして軸位置。

また、私は DirectX SKD のみを使用し、SlimDX などは使用しません。

4

1 に答える 1

1

おそらく、管理された形式で DirectX とやり取りする必要があります。詳細については、SO に関するこの記事を参照してください。ただし、基本的には、入力をポーリングしてから独自のイベントを処理するだけです。「どうすればこれを実現できるか」以外の質問がある場合は、お気軽にコメントしてください。可能な場合は編集します。

于 2013-11-01T12:55:49.563 に答える