Пример #1
0
        internal void Load(BinaryReader reader)
        {
            ClearBindings();

            var bindingCount = reader.ReadInt32();

            for (int i = 0; i < bindingCount; i++)
            {
                var           bindingSourceType = (BindingSourceType)reader.ReadInt32();
                BindingSource bindingSource;


                switch (bindingSourceType)
                {
                case BindingSourceType.DeviceBindingSource:
                    bindingSource = new DeviceBindingSource();
                    break;

                case BindingSourceType.KeyBindingSource:
                    bindingSource = new KeyBindingSource();
                    break;

                case BindingSourceType.MouseBindingSource:
                    bindingSource = new MouseBindingSource();
                    break;

                default:
                    throw new Exception("Don't know how to load BindingSourceType: " + bindingSourceType);
                }

                bindingSource.Load(reader);
                AddBinding(bindingSource);
            }
        }
Пример #2
0
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeControllers || device.IsUnknown)
            {
                return(null);
            }

            if (detectFound != InputControlType.None)
            {
                if (!IsPressed(detectFound, device))
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new DeviceBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var control = ListenForControl(listenOptions, device);

            if (control != InputControlType.None)
            {
                if (detectPhase == 1)
                {
                    detectFound = control;
                    detectPhase = 2; // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1; // Wait for press.
                }
            }

            return(null);
        }