예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            XInput.GetCapabilities(0, DeviceQueryType.Gamepad, out Capabilities c);
            if (c.Type == DeviceType.Gamepad)
            {
                label12.Text   = "Controller Connected";
                timer1.Enabled = true;

                numericUpDown1.Enabled = false;
                numericUpDown2.Enabled = false;
                numericUpDown3.Enabled = false;
            }
        }
예제 #2
0
        public JoystickCapabilities GetCapabilities(int index)
        {
            XInputDeviceCapabilities xcaps;
            XInputErrorCode          error = xinput.GetCapabilities(
                (XInputUserIndex)index,
                XInputCapabilitiesFlags.Default,
                out xcaps);

            if (error == XInputErrorCode.Success)
            {
                //GamePadType type = TranslateSubType(xcaps.SubType);
                int buttons = TranslateButtons(xcaps.GamePad.Buttons);
                int axes    = TranslateAxes(ref xcaps.GamePad);

                return(new JoystickCapabilities(axes, buttons, 1, true));
            }
            return(new JoystickCapabilities());
        }
예제 #3
0
        void UpdateStatus()
        {
            var capabilities = new XInput.XINPUT_CAPABILITIES();

            var conneced = XInput.GetCapabilities(ControllerNo.Value, XInput.XINPUT_FLAG_GAMEPAD, ref capabilities);

            if (conneced == (uint)XInput.ErrCode.ERROR_SUCCESS)
            {
                //capabilities.Typeから値を取得すると1になって、バッテリー情報が取れない。ので決め打ち。ゲームパッドしか使えない仕様。仕様です。
                const byte BATTERY_DEVTYPE_GAMEPAD = 0;
                var        battryInfo = new XInput.XINPUT_BATTERY_INFORMATION();
                var        sucsess    = XInput.GetBatteryInformation(ControllerNo.Value, BATTERY_DEVTYPE_GAMEPAD, ref battryInfo);

                BatteryLevel.Value = battryInfo.BatteryLevel;
                IsConnected.Value  = true;
            }
            else if (conneced == (uint)XInput.ErrCode.ERROR_DEVICE_NOT_CONNECTED)
            {
                BatteryLevel.Value = 0;
                IsConnected.Value  = false;
            }
            Stauts.Value = $"Controller {ControllerNo.Value + 1}: {(IsConnected.Value ? "Connect" : "Disconnect")}";
        }