コード例 #1
0
ファイル: GameController.cs プロジェクト: yy520a/XOutput
        private XboxInputMessage GetMessage(DeviceInputChangedEventArgs e)
        {
            XboxInputMessage message = new XboxInputMessage();

            if (e.ChangedDPads.Any())
            {
                message.UP    = XInput.GetBool(XInputTypes.UP);
                message.DOWN  = XInput.GetBool(XInputTypes.DOWN);
                message.LEFT  = XInput.GetBool(XInputTypes.LEFT);
                message.RIGHT = XInput.GetBool(XInputTypes.RIGHT);
            }
            foreach (var value in e.ChangedValues)
            {
                if (value.IsButton)
                {
                    XInputTypes type = (XInputTypes)Enum.Parse(typeof(XInputTypes), value.DisplayName);
                    switch (type)
                    {
                    case XInputTypes.A:
                        message.A = value.Value > 0.5;
                        break;

                    case XInputTypes.B:
                        message.B = value.Value > 0.5;
                        break;

                    case XInputTypes.X:
                        message.X = value.Value > 0.5;
                        break;

                    case XInputTypes.Y:
                        message.Y = value.Value > 0.5;
                        break;

                    case XInputTypes.L1:
                        message.L1 = value.Value > 0.5;
                        break;

                    case XInputTypes.R1:
                        message.R1 = value.Value > 0.5;
                        break;

                    case XInputTypes.L3:
                        message.L3 = value.Value > 0.5;
                        break;

                    case XInputTypes.R3:
                        message.R3 = value.Value > 0.5;
                        break;

                    case XInputTypes.Start:
                        message.Start = value.Value > 0.5;
                        break;

                    case XInputTypes.Back:
                        message.Back = value.Value > 0.5;
                        break;

                    case XInputTypes.Home:
                        message.Home = value.Value > 0.5;
                        break;
                    }
                }
                else
                {
                    XInputTypes type = (XInputTypes)Enum.Parse(typeof(XInputTypes), value.DisplayName);
                    switch (type)
                    {
                    case XInputTypes.L2:
                        message.L2 = value.Value;
                        break;

                    case XInputTypes.R2:
                        message.R2 = value.Value;
                        break;

                    case XInputTypes.LX:
                        message.LX = value.Value;
                        break;

                    case XInputTypes.LY:
                        message.LY = value.Value;
                        break;

                    case XInputTypes.RX:
                        message.RX = value.Value;
                        break;

                    case XInputTypes.RY:
                        message.RY = value.Value;
                        break;
                    }
                }
            }
            return(message);
        }