Exemple #1
0
        private RawButtonInputReport ExtractRawButtonInputReport(NotifyInputEventArgs e, RoutedEvent Event)
        {
            RawButtonInputReport buttonInput = null;

            InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;

            if (input != null)
            {
                if (input.Report is RawButtonInputReport && input.RoutedEvent == Event)
                {
                    buttonInput = (RawButtonInputReport)input.Report;
                }
            }

            return(buttonInput);
        }
Exemple #2
0
        private RawButtonActions GetNonRedundantActions(NotifyInputEventArgs e)
        {
            RawButtonActions actions;

            // The CLR throws a null-ref exception if it tries to unbox a
            // null.  So we have to special case that.
            object o = e.StagingItem.GetData(_tagNonRedundantActions);

            if (o != null)
            {
                actions = (RawButtonActions)o;
            }
            else
            {
                actions = new RawButtonActions();
            }

            return(actions);
        }
        private RawButtonInputReport ExtractRawButtonInputReport(NotifyInputEventArgs e, RoutedEvent Event)
        {
            RawButtonInputReport buttonInput = null;

            InputReportEventArgs input = e.StagingItem.Input as InputReportEventArgs;
            if (input != null)
            {
                if (input.Report is RawButtonInputReport && input.RoutedEvent == Event)
                {
                    buttonInput = (RawButtonInputReport)input.Report;
                }
            }

            return buttonInput;
        }
        private RawButtonActions GetNonRedundantActions(NotifyInputEventArgs e)
        {
            RawButtonActions actions;

            // The CLR throws a null-ref exception if it tries to unbox a
            // null.  So we have to special case that.
            object o = e.StagingItem.GetData(_tagNonRedundantActions);
            if (o != null)
            {
                actions = (RawButtonActions)o;
            }
            else
            {
                actions = new RawButtonActions();
            }

            return actions;
        }
        private void PreNotifyInput(object sender, NotifyInputEventArgs e)
        {
            RawButtonInputReport buttonInput = ExtractRawButtonInputReport(e, InputManager.PreviewInputReportEvent);
            if (buttonInput != null)
            {
                CheckForDisconnectedFocus();
                /*

REFACTOR --

                the keyboard device is only active per app domain basis -- so like if your app domain doesn't have
                focus your keyboard device is not going to give you the real state of the keyboard.

                When it gets focus, it needs to know about this somehow.   We could use this keyboard action
                type stuff to do so.  Though this design really seem to be influenced a lot from living in
                the windows world.

                Essentially the input stack is being used like a message pump to say, hey dude you can
                use the keyboard now -- it's not real input, it's more or less a message.

                It could be interesting for elements to know about this -- since I think
                they will probalby still have focus (or do they get a Got and Lost Focus when the keyboard activates -- I don't think so,
                we need to know what we were focused on when the window gets focus again.

                So maybe elements want to stop some animation or something when input focus moves away from the activesource, and
                start them again later.  Could be interesting.
*/

                if ((buttonInput.Actions & RawButtonActions.Activate) == RawButtonActions.Activate)
                {
                    //System.Console.WriteLine("Initializing the button state.");

#if TRACK_BUTTON_STATE
                    // Clear out our key state storage.
                    for (int i = 0; i < _buttonState.Length; i++)
                    {
                        _buttonState[i] = 0;
                    }

#endif
                    // we are now active.
                    // we should track which source is active so we don't confuse deactivations.
                    _isActive = true;
                }

                // Generally, we need to check against redundant actions.
                // We never prevet the raw event from going through, but we
                // will only generate the high-level events for non-redundant
                // actions.  We store the set of non-redundant actions in
                // the dictionary of this event.

                // If the input is reporting a button down, the action is never
                // considered redundant.
                if ((buttonInput.Actions & RawButtonActions.ButtonDown) == RawButtonActions.ButtonDown)
                {
                    RawButtonActions actions = GetNonRedundantActions(e);
                    actions |= RawButtonActions.ButtonDown;
                    e.StagingItem.SetData(_tagNonRedundantActions, actions);

                    // Pass along the button that was pressed, and update our state.
                    e.StagingItem.SetData(_tagButton, buttonInput.Button);

#if TRACK_BUTTON_STATE
                    ButtonState buttonState = GetButtonState(buttonInput.Button);

                    if ((buttonState & ButtonState.Down) == ButtonState.Down)
                    {
                        buttonState = ButtonState.Down | ButtonState.Held;
                    }
                    else
                    {
                        buttonState |= ButtonState.Down;
                    }

                    SetButtonState(buttonInput.Button, buttonState);
#endif

                    // Tell the InputManager that the MostRecentDevice is us.
                    if (_inputManager != null && _inputManager.MostRecentInputDevice != this)
                    {
                        _inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }

                // need to detect redundant ups.
                if ((buttonInput.Actions & RawButtonActions.ButtonUp) == RawButtonActions.ButtonUp)
                {
                    RawButtonActions actions = GetNonRedundantActions(e);
                    actions |= RawButtonActions.ButtonUp;
                    e.StagingItem.SetData(_tagNonRedundantActions, actions);

                    // Pass along the button that was pressed, and update our state.
                    e.StagingItem.SetData(_tagButton, buttonInput.Button);

#if TRACK_BUTTON_STATE
                    ButtonState buttonState = GetButtonState(buttonInput.Button);

                    if ((buttonState & ButtonState.Down) == ButtonState.Down)
                    {
                        buttonState &= (~ButtonState.Down) & (ButtonState.Down | ButtonState.Held);
                    }
                    else
                    {
                        buttonState |= ButtonState.Held;
                    }

                    SetButtonState(buttonInput.Button, buttonState);
#endif

                    // Tell the InputManager that the MostRecentDevice is us.
                    if (_inputManager != null && _inputManager.MostRecentInputDevice != this)
                    {
                        _inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }
            }

            // On ButtonDown, we might need to set the Repeat flag

            if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonDownEvent)
            {
                CheckForDisconnectedFocus();

                ButtonEventArgs args = (ButtonEventArgs)e.StagingItem.Input;

                // Is this the same as the previous button?
                if (_previousButton == args.Button)
                {
                    // Yes, this is a repeat (we got the buttondown for it twice, with no ButtonUp in between)
                    // what about chording?
                    args._isRepeat = true;
                }

                // Otherwise, keep this button to check against next time.
                else
                {
                    _previousButton = args.Button;
                    args._isRepeat = false;
                }

            }

            // On ButtonUp, we clear Repeat flag
            else if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonUpEvent)
            {
                CheckForDisconnectedFocus();

                ButtonEventArgs args = (ButtonEventArgs)e.StagingItem.Input;
                args._isRepeat = false;

                // Clear _previousButton, so that down/up/down/up doesn't look like a repeat
                _previousButton = Button.None;

            }
        }
Exemple #6
0
        private void PreNotifyInput(object sender, NotifyInputEventArgs e)
        {
            RawButtonInputReport buttonInput = ExtractRawButtonInputReport(e, InputManager.PreviewInputReportEvent);

            if (buttonInput != null)
            {
                CheckForDisconnectedFocus();

                /*
                 *
                 * REFACTOR --
                 *
                 * the keyboard device is only active per app domain basis -- so like if your app domain doesn't have
                 * focus your keyboard device is not going to give you the real state of the keyboard.
                 *
                 * When it gets focus, it needs to know about this somehow.   We could use this keyboard action
                 * type stuff to do so.  Though this design really seem to be influenced a lot from living in
                 * the windows world.
                 *
                 * Essentially the input stack is being used like a message pump to say, hey dude you can
                 * use the keyboard now -- it's not real input, it's more or less a message.
                 *
                 * It could be interesting for elements to know about this -- since I think
                 * they will probalby still have focus (or do they get a Got and Lost Focus when the keyboard activates -- I don't think so,
                 * we need to know what we were focused on when the window gets focus again.
                 *
                 * So maybe elements want to stop some animation or something when input focus moves away from the activesource, and
                 * start them again later.  Could be interesting.
                 */

                if ((buttonInput.Actions & RawButtonActions.Activate) == RawButtonActions.Activate)
                {
                    //System.Console.WriteLine("Initializing the button state.");

#if TRACK_BUTTON_STATE
                    // Clear out our key state storage.
                    for (int i = 0; i < _buttonState.Length; i++)
                    {
                        _buttonState[i] = 0;
                    }
#endif
                    // we are now active.
                    // we should track which source is active so we don't confuse deactivations.
                    _isActive = true;
                }

                // Generally, we need to check against redundant actions.
                // We never prevet the raw event from going through, but we
                // will only generate the high-level events for non-redundant
                // actions.  We store the set of non-redundant actions in
                // the dictionary of this event.

                // If the input is reporting a button down, the action is never
                // considered redundant.
                if ((buttonInput.Actions & RawButtonActions.ButtonDown) == RawButtonActions.ButtonDown)
                {
                    RawButtonActions actions = GetNonRedundantActions(e);
                    actions |= RawButtonActions.ButtonDown;
                    e.StagingItem.SetData(_tagNonRedundantActions, actions);

                    // Pass along the button that was pressed, and update our state.
                    e.StagingItem.SetData(_tagButton, buttonInput.Button);

#if TRACK_BUTTON_STATE
                    ButtonState buttonState = GetButtonState(buttonInput.Button);

                    if ((buttonState & ButtonState.Down) == ButtonState.Down)
                    {
                        buttonState = ButtonState.Down | ButtonState.Held;
                    }
                    else
                    {
                        buttonState |= ButtonState.Down;
                    }

                    SetButtonState(buttonInput.Button, buttonState);
#endif

                    // Tell the InputManager that the MostRecentDevice is us.
                    if (_inputManager != null)
                    {
                        _inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }

                // need to detect redundant ups.
                if ((buttonInput.Actions & RawButtonActions.ButtonUp) == RawButtonActions.ButtonUp)
                {
                    RawButtonActions actions = GetNonRedundantActions(e);
                    actions |= RawButtonActions.ButtonUp;
                    e.StagingItem.SetData(_tagNonRedundantActions, actions);

                    // Pass along the button that was pressed, and update our state.
                    e.StagingItem.SetData(_tagButton, buttonInput.Button);

#if TRACK_BUTTON_STATE
                    ButtonState buttonState = GetButtonState(buttonInput.Button);

                    if ((buttonState & ButtonState.Down) == ButtonState.Down)
                    {
                        buttonState &= (~ButtonState.Down) & (ButtonState.Down | ButtonState.Held);
                    }
                    else
                    {
                        buttonState |= ButtonState.Held;
                    }

                    SetButtonState(buttonInput.Button, buttonState);
#endif

                    // Tell the InputManager that the MostRecentDevice is us.
                    if (_inputManager != null)
                    {
                        _inputManager.MostRecentInputDevice = (InputDevice)this;
                    }
                }
            }

            // On ButtonDown, we might need to set the Repeat flag

            if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonDownEvent)
            {
                CheckForDisconnectedFocus();

                ButtonEventArgs args = (ButtonEventArgs)e.StagingItem.Input;

                // Is this the same as the previous button?
                if (_previousButton == args.Button)
                {
                    // Yes, this is a repeat (we got the buttondown for it twice, with no ButtonUp in between)
                    // what about chording?
                    args._isRepeat = true;
                }

                // Otherwise, keep this button to check against next time.
                else
                {
                    _previousButton = args.Button;
                    args._isRepeat  = false;
                }
            }

            // On ButtonUp, we clear Repeat flag
            else if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonUpEvent)
            {
                CheckForDisconnectedFocus();

                ButtonEventArgs args = (ButtonEventArgs)e.StagingItem.Input;
                args._isRepeat = false;

                // Clear _previousButton, so that down/up/down/up doesn't look like a repeat
                _previousButton = Button.None;
            }
        }