public void RaiseButton(HardwareButton button, bool state, DateTime time)
        {
            RawButtonInputReport report = new RawButtonInputReport(null, time, button, state ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown);
            InputReportArgs      args   = new InputReportArgs(InputManager.CurrentInputManager.ButtonDevice, report);

            this.application.Dispatcher.BeginInvoke(_ => this.buttonSite.ReportInput(args.Device, args.Report), null);
        }
Esempio n. 2
0
        private static HardwareKeys ButtonConvert(HardwareButton button)
        {
            switch (button)
            {
            case HardwareButton.B1:
                return(HardwareKeys.ApplicationKey1);

            case HardwareButton.B2:
                return(HardwareKeys.ApplicationKey2);

            case HardwareButton.B3:
                return(HardwareKeys.ApplicationKey3);

            case HardwareButton.B4:
                return(HardwareKeys.ApplicationKey4);

            case HardwareButton.B5:
                return(HardwareKeys.ApplicationKey5);

            case HardwareButton.B6:
                return(HardwareKeys.ApplicationKey6);

            default:
                throw new ArgumentException("Invalid button value");
            }
            //return (HardwareKeys) button;
        }
 public ButtonState GetButtonState(HardwareButton button)
 {
     if (HardwareButton.LastSystemDefinedButton <= button || button <= HardwareButton.None)
     {
         throw new ArgumentOutOfRangeException(nameof(button), "invalid enum");
     }
     return((ButtonState)((int)this._buttonState[(int)button / 4] >> (int)button % 4 & 3));
 }
        internal void SetButtonState(HardwareButton button, ButtonState state)
        {
            this.VerifyAccess();
            if (HardwareButton.LastSystemDefinedButton <= button || button <= HardwareButton.None)
            {
                throw new ArgumentOutOfRangeException(nameof(button), "invalid enum");
            }
            int  index = (int)button / 4;
            int  num1  = (int)button % 4;
            byte num2  = (byte)((uint)(byte)((uint)this._buttonState[index] & (uint)~(byte)(3 << num1)) | (uint)(byte)((uint)state << num1));

            this._buttonState[index] = num2;
        }
Esempio n. 5
0
        public static void Bind(HardwareButton button, string actionName)
        {
            var key = ButtonConvert(button);

            Unbind(button);

            bindings[key] = actionName;
            buttons.Add(
                new CE.HardwareButton()
            {
                HardwareKey       = key,
                AssociatedControl = ConfigManager.MainForm,
            });
        }
Esempio n. 6
0
        public static void Unbind(HardwareButton key)
        {
            var boundButton = buttons.Find(
                delegate(CE.HardwareButton button)
            {
                return(button.HardwareKey == ButtonConvert(key));
            });

            if (boundButton != null)
            {
                buttons.Remove(boundButton);
                boundButton.AssociatedControl = null;
                boundButton.Dispose();
                bindings.Remove(ButtonConvert(key));
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Returns the state of the specified button.
        /// </summary>
        public ButtonState GetButtonState(HardwareButton button)
        {
#if TRACK_BUTTON_STATE
            if ((int)HardwareButton.LastSystemDefinedButton <= (int)button || (int)button <= 0)
            {
                throw new ArgumentOutOfRangeException("button", "invalid enum");
            }

            var index = (int)button / 4;
            var state = (this._buttonState[index] >> ((int)button % 4)) & 0x3;

            return((ButtonState)state);
#else
            return(ButtonState.None);
#endif
        }
Esempio n. 8
0
        internal void SetButtonState(HardwareButton button, ButtonState state)
        {
            //If the PreNotifyInput event sent by the InputManager is always sent by the
            //correct thread, this is redundant. Also, why is this function 'internal'
            //when we only access it from inside this class?
            VerifyAccess();

            if ((int)HardwareButton.LastSystemDefinedButton <= (int)button || (int)button <= 0)
            {
                throw new ArgumentOutOfRangeException("button", "invalid enum");
            }

            var index = (int)button / 4;
            var shift = ((int)button % 4);

            var newState = this._buttonState[index];

            newState &= (byte)(~((byte)(0x3 << shift)));
            newState |= (byte)((int)state << shift);

            this._buttonState[index] = newState;
        }
Esempio n. 9
0
 /// <summary>
 ///     Returns whether or not the specified button is down.
 /// </summary>
 public bool IsButtonDown(HardwareButton button) => GetButtonState(button) == ButtonState.Down;
Esempio n. 10
0
        public static string GetBinding(HardwareButton button)
        {
            var key = ButtonConvert(button);

            return(bindings.ContainsKey(key) ? bindings[key] : String.Empty);
        }
Esempio n. 11
0
 /// <summary>
 ///     Returns the state of the specified button.
 /// </summary>
 public static ButtonState GetButtonState(HardwareButton button) => PrimaryDevice.GetButtonState(button);
Esempio n. 12
0
 public bool IsButtonUp(HardwareButton button)
 {
     return(this.GetButtonState(button) == ButtonState.None);
 }
Esempio n. 13
0
 public bool IsButtonHeld(HardwareButton button)
 {
     return(this.GetButtonState(button) == ButtonState.Held);
 }
Esempio n. 14
0
 public bool IsButtonDown(HardwareButton button)
 {
     return(this.GetButtonState(button) == ButtonState.Down);
 }
Esempio n. 15
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonDownEvent)
            {
                this.CheckForDisconnectedFocus();
                if (!e.StagingItem.Input.Handled)
                {
                    ButtonEventArgs input            = (ButtonEventArgs)e.StagingItem.Input;
                    ButtonEventArgs buttonEventArgs1 = new ButtonEventArgs(this, input.InputSource, input.Timestamp, input.Button);
                    buttonEventArgs1._isRepeat   = input.IsRepeat;
                    buttonEventArgs1.RoutedEvent = Buttons.ButtonDownEvent;
                    ButtonEventArgs buttonEventArgs2 = buttonEventArgs1;
                    e.PushInput((InputEventArgs)buttonEventArgs2, e.StagingItem);
                }
            }
            if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonUpEvent)
            {
                this.CheckForDisconnectedFocus();
                if (!e.StagingItem.Input.Handled)
                {
                    ButtonEventArgs input            = (ButtonEventArgs)e.StagingItem.Input;
                    ButtonEventArgs buttonEventArgs1 = new ButtonEventArgs(this, input.InputSource, input.Timestamp, input.Button);
                    buttonEventArgs1.RoutedEvent = Buttons.ButtonUpEvent;
                    ButtonEventArgs buttonEventArgs2 = buttonEventArgs1;
                    e.PushInput((InputEventArgs)buttonEventArgs2, e.StagingItem);
                }
            }
            RawButtonInputReport buttonInputReport = this.ExtractRawButtonInputReport((NotifyInputEventArgs)e, InputManager.InputReportEvent);

            if (buttonInputReport == null)
            {
                return;
            }
            this.CheckForDisconnectedFocus();
            if (!e.StagingItem.Input.Handled)
            {
                int redundantActions = (int)this.GetNonRedundantActions((NotifyInputEventArgs)e);
                if ((redundantActions & 1) == 1)
                {
                    HardwareButton data = (HardwareButton)e.StagingItem.GetData(this._tagButton);
                    if (data != HardwareButton.None)
                    {
                        ButtonEventArgs buttonEventArgs1 = new ButtonEventArgs(this, buttonInputReport.InputSource, buttonInputReport.Timestamp, data);
                        buttonEventArgs1.RoutedEvent = Buttons.PreviewButtonDownEvent;
                        ButtonEventArgs buttonEventArgs2 = buttonEventArgs1;
                        e.PushInput((InputEventArgs)buttonEventArgs2, e.StagingItem);
                    }
                }
                if ((redundantActions & 2) == 2)
                {
                    HardwareButton data = (HardwareButton)e.StagingItem.GetData(this._tagButton);
                    if (data != HardwareButton.None)
                    {
                        ButtonEventArgs buttonEventArgs1 = new ButtonEventArgs(this, buttonInputReport.InputSource, buttonInputReport.Timestamp, data);
                        buttonEventArgs1.RoutedEvent = Buttons.PreviewButtonUpEvent;
                        ButtonEventArgs buttonEventArgs2 = buttonEventArgs1;
                        e.PushInput((InputEventArgs)buttonEventArgs2, e.StagingItem);
                    }
                }
            }
            if ((buttonInputReport.Actions & RawButtonActions.Deactivate) != RawButtonActions.Deactivate || !this._isActive)
            {
                return;
            }
            this._isActive = false;
            this.ChangeFocus((UIElement)null, e.StagingItem.Input.Timestamp);
        }
Esempio n. 16
0
        private void PreNotifyInput(object sender, NotifyInputEventArgs e)
        {
            RawButtonInputReport buttonInputReport = this.ExtractRawButtonInputReport(e, InputManager.PreviewInputReportEvent);

            if (buttonInputReport != null)
            {
                this.CheckForDisconnectedFocus();
                if ((buttonInputReport.Actions & RawButtonActions.Activate) == RawButtonActions.Activate)
                {
                    for (int index = 0; index < this._buttonState.Length; ++index)
                    {
                        this._buttonState[index] = (byte)0;
                    }
                    this._isActive = true;
                }
                if ((buttonInputReport.Actions & RawButtonActions.ButtonDown) == RawButtonActions.ButtonDown)
                {
                    RawButtonActions rawButtonActions = this.GetNonRedundantActions(e) | RawButtonActions.ButtonDown;
                    e.StagingItem.SetData(this._tagNonRedundantActions, (object)rawButtonActions);
                    e.StagingItem.SetData(this._tagButton, (object)buttonInputReport.Button);
                    ButtonState buttonState = this.GetButtonState(buttonInputReport.Button);
                    ButtonState state       = (buttonState & ButtonState.Down) != ButtonState.Down ? buttonState | ButtonState.Down : ButtonState.Down | ButtonState.Held;
                    this.SetButtonState(buttonInputReport.Button, state);
                    if (this._inputManager != null && this._inputManager.MostRecentInputDevice != this)
                    {
                        this._inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }
                if ((buttonInputReport.Actions & RawButtonActions.ButtonUp) == RawButtonActions.ButtonUp)
                {
                    RawButtonActions rawButtonActions = this.GetNonRedundantActions(e) | RawButtonActions.ButtonUp;
                    e.StagingItem.SetData(this._tagNonRedundantActions, (object)rawButtonActions);
                    e.StagingItem.SetData(this._tagButton, (object)buttonInputReport.Button);
                    ButtonState buttonState = this.GetButtonState(buttonInputReport.Button);
                    ButtonState state       = (buttonState & ButtonState.Down) != ButtonState.Down ? buttonState | ButtonState.Held : buttonState & ButtonState.Held;
                    this.SetButtonState(buttonInputReport.Button, state);
                    if (this._inputManager != null && this._inputManager.MostRecentInputDevice != this)
                    {
                        this._inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }
            }
            if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonDownEvent)
            {
                this.CheckForDisconnectedFocus();
                ButtonEventArgs input = (ButtonEventArgs)e.StagingItem.Input;
                if (this._previousButton == input.Button)
                {
                    input._isRepeat = true;
                }
                else
                {
                    this._previousButton = input.Button;
                    input._isRepeat      = false;
                }
            }
            else
            {
                if (e.StagingItem.Input.RoutedEvent != Buttons.PreviewButtonUpEvent)
                {
                    return;
                }
                this.CheckForDisconnectedFocus();
                ((ButtonEventArgs)e.StagingItem.Input)._isRepeat = false;
                this._previousButton = HardwareButton.None;
            }
        }
Esempio n. 17
0
 /// <summary>
 ///     Returns whether or not the specified button is up.
 /// </summary>
 public bool IsButtonUp(HardwareButton button) => GetButtonState(button) == ButtonState.None;
Esempio n. 18
0
 public static ButtonState GetButtonState(HardwareButton button)
 {
     return(PrimaryDevice.GetButtonState(button));
 }
Esempio n. 19
0
 /// <summary>
 ///     Returns whether or not the specified button is held.
 /// </summary>
 public bool IsButtonHeld(HardwareButton button) => GetButtonState(button) == ButtonState.Held;
Esempio n. 20
0
 /// <summary>
 ///     Returns whether or not the specified button is down.
 /// </summary>
 public static bool IsButtonDown(HardwareButton button) => PrimaryDevice.IsButtonDown(button);
 /// <summary>
 ///     Constructs an instance of the ButtonEventArgs class.
 /// </summary>
 /// <param name="buttonDevice">
 ///     The button device associated with this event.
 /// </param>
 /// <param name="timestamp">
 ///     The time when the input occured. (machine time)
 /// </param>
 /// <param name="button">
 ///     The button referenced by the event.
 /// </param>
 public ButtonEventArgs(ButtonDevice buttonDevice, PresentationSource inputSource, DateTime timestamp, HardwareButton button)
     : base(buttonDevice, timestamp)
 {
     this.InputSource = inputSource;
     this.Button      = button;
 }
Esempio n. 22
0
 /// <summary>
 ///     Returns whether or not the specified button is held.
 /// </summary>
 public static bool IsButtonHeld(HardwareButton button) => PrimaryDevice.IsButtonHeld(button);
Esempio n. 23
0
 public static bool IsButtonUp(HardwareButton button)
 {
     return(PrimaryDevice.IsButtonUp(button));
 }
 public RawButtonInputReport(PresentationSource inputSource, DateTime timestamp, HardwareButton button, RawButtonActions actions) : base(inputSource, timestamp)
 {
     this.Button  = button;
     this.Actions = actions;
 }