void Interrupt(uint data1, uint data2, TimeSpan time) { RawButtonActions action = (data2 != 0) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; RawButtonInputReport report = new RawButtonInputReport(sink.source, time, button, action); // Queue the button press to the input provider site. sink.Dispatcher.BeginInvoke(sink.callback, report); }
void Interrupt(Cpu.Pin port, bool state, TimeSpan time) { RawButtonActions action = state ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; RawButtonInputReport report = new RawButtonInputReport(sink.source, time, button, action); // Queue the button press to the input provider site. sink.Dispatcher.BeginInvoke(sink.callback, report); }
private void Pin_ValueChanged(object sender, GpioPinValueChangedEventArgs e) { RawButtonActions action = (e.Edge == GpioPinEdge.FallingEdge) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; DateTime time = DateTime.UtcNow; RawButtonInputReport report = new RawButtonInputReport(sink.source, time, button, action); // Queue the button press to the input provider site. sink.Dispatcher.BeginInvoke(sink.callback, new InputReportArgs(buttonDevice, report)); }
void Interrupt(uint data1, uint data2, DateTime time) { // queue the button press to the input provider site. RawButtonActions action = (data2 != 0) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; RawButtonInputReport report = new RawButtonInputReport(_sink._source, time, _button, action); _sink.Dispatcher.BeginInvoke(_sink._callback, new InputReportArgs(_buttonDevice, report)); }
private void Pin_ValueChanged(object sender, PinValueChangedEventArgs e) { RawButtonActions action = (e.ChangeType == PinEventTypes.Falling) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; // Create a time, should be from the pin_ValueChanged event. DateTime time = DateTime.UtcNow; RawButtonInputReport report = new RawButtonInputReport(sink.source, time, button, action); // Queue the button press to the input provider site. sink.Dispatcher.BeginInvoke(sink.callback, new InputReportArgs(buttonDevice, report)); }
void Interrupt(uint data1, uint data2, DateTime time) { RawButtonActions action = (data2 != 0) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; RawButtonInputReport report = new RawButtonInputReport(null, time, m_button, action); // Queue the button press to the handler. m_sink.m_dispatcher.BeginInvoke(delegate(object arg) { m_sink.m_buttonInputHandler((InputReportArgs)arg); return(null); }, new InputReportArgs(m_buttonDevice, report)); }
void Interrupt(uint data1, uint data2, DateTime time) #endif { RawButtonActions action = (data2 != 0) ? RawButtonActions.ButtonUp : RawButtonActions.ButtonDown; RawButtonInputReport report = new RawButtonInputReport( sink.source, time, button, action); // Queue the button press to the input provider site. #if MF_FRAMEWORK_VERSION_V3_0 sink.Dispatcher.BeginInvoke(sink.callback, report); #else sink.Dispatcher.BeginInvoke(sink.callback, new InputReportArgs(buttonDevice, report)); #endif }
private void HandleTouch(RawButtonActions action, TouchScreenEventArgs eventArgs) { dispatcher.Invoke( new TimeSpan(0, 0, 3), delegate(object arg) { Button button = (Button)eventArgs.Target; RawButtonInputReport report = new RawButtonInputReport(this.presentationSource, eventArgs.TimeStamp, button, action); bool handled = site.ReportInput(this.buttonDevice, report); if (!handled) { ButtonEventArgs buttonEventArgs = new ButtonEventArgs(this.buttonDevice, this.presentationSource, eventArgs.TimeStamp, button); this.OnButtonUp(buttonEventArgs); } return(null); }, null); }
/// <summary> /// Creates new instance of input provider /// </summary> /// <param name="source">Presentation source</param> /// <param name="controller">TV Remote Receiver controller driver</param> /// <param name="address">Address of device. Use -1 for everything.</param> /// <param name="buttons">Command to WPF button maping</param> public TVRemoteInputProvider(PresentationSource source, TVRemoteReceiver controller, int address, TVRemoteButtonPad[] buttons) { // Set the input source. this.source = source; // Register our object as an input source with the input manager and get back an // InputProviderSite object which forwards the input report to the input manager, // which then places the input in the staging area. site = InputManager.CurrentInputManager.RegisterInputProvider(this); // Create a delegate that refers to the InputProviderSite object's ReportInput method callback = new ReportInputCallback(site.ReportInput); Dispatcher = Dispatcher.CurrentDispatcher; deviceAddress = address; this.buttons = buttons; ButtonAction = RawButtonActions.ButtonUp; controller.DataReceived += new TVRemoteReceiver.TVRemoteDataHandler(controller_DataReceived); }
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. var o = e.StagingItem.GetData(this._tagNonRedundantActions); if (o != null) { actions = (RawButtonActions)o; } else { actions = new RawButtonActions(); } return(actions); }
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; } }
public RawButtonInputReport(PresentationSource inputSource, DateTime timestamp, HardwareButton button, RawButtonActions actions) : base(inputSource, timestamp) { this.Button = button; this.Actions = actions; }
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; }
void ReportInput(DateTime TimeStamp, Button TheButton, RawButtonActions Actions) { RawButtonInputReport report = new RawButtonInputReport(this.PresentationSource, TimeStamp, TheButton, Actions); this.Dispatcher.BeginInvoke(this.ReportInputFunc, new object[] { report }); }
/// <summary> /// Constructs an instance of the RawKeyboardInputReport class. /// </summary> /// <param name="inputSource"> /// source of the input /// </param> /// <param name="timestamp"> /// The time when the input occured. /// </param> public RawButtonInputReport(PresentationSource inputSource, DateTime timestamp, Button button, RawButtonActions actions) : base(inputSource, timestamp) { Button = button; Actions = actions; }
void ReportInput( DateTime TimeStamp, Button TheButton, RawButtonActions Actions ) { RawButtonInputReport report = new RawButtonInputReport( this.PresentationSource, TimeStamp, TheButton, Actions ); this.Dispatcher.BeginInvoke( this.ReportInputFunc, new object[ ] { report } ); }
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; } }
private void PostProcessInput(object sender, ProcessInputEventArgs e) { // PreviewButtonDown --> ButtonDown if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonDownEvent) { CheckForDisconnectedFocus(); if (!e.StagingItem.Input.Handled) { ButtonEventArgs previewButtonDown = (ButtonEventArgs)e.StagingItem.Input; ButtonEventArgs buttonDown = new ButtonEventArgs(this, previewButtonDown.InputSource, previewButtonDown.Timestamp, previewButtonDown.Button); buttonDown._isRepeat = previewButtonDown.IsRepeat; buttonDown.RoutedEvent = Buttons.ButtonDownEvent; e.PushInput(buttonDown, e.StagingItem); } } // PreviewButtonUp --> ButtonUp if (e.StagingItem.Input.RoutedEvent == Buttons.PreviewButtonUpEvent) { CheckForDisconnectedFocus(); if (!e.StagingItem.Input.Handled) { ButtonEventArgs previewButtonUp = (ButtonEventArgs)e.StagingItem.Input; ButtonEventArgs buttonUp = new ButtonEventArgs(this, previewButtonUp.InputSource, previewButtonUp.Timestamp, previewButtonUp.Button); buttonUp.RoutedEvent = Buttons.ButtonUpEvent; e.PushInput(buttonUp, e.StagingItem); } } RawButtonInputReport buttonInput = ExtractRawButtonInputReport(e, InputManager.InputReportEvent); if (buttonInput != null) { CheckForDisconnectedFocus(); if (!e.StagingItem.Input.Handled) { // In general, this is where we promote the non-redundant // reported actions to our premier events. RawButtonActions actions = GetNonRedundantActions(e); // Raw --> PreviewButtonDown if ((actions & RawButtonActions.ButtonDown) == RawButtonActions.ButtonDown) { Button button = (Button)e.StagingItem.GetData(_tagButton); if (button != Button.None) { ButtonEventArgs previewButtonDown = new ButtonEventArgs(this, buttonInput.InputSource, buttonInput.Timestamp, button); previewButtonDown.RoutedEvent = Buttons.PreviewButtonDownEvent; e.PushInput(previewButtonDown, e.StagingItem); } } // Raw --> PreviewButtonUp if ((actions & RawButtonActions.ButtonUp) == RawButtonActions.ButtonUp) { Button button = (Button)e.StagingItem.GetData(_tagButton); if (button != Button.None) { ButtonEventArgs previewButtonUp = new ButtonEventArgs(this, buttonInput.InputSource, buttonInput.Timestamp, button); previewButtonUp.RoutedEvent = Buttons.PreviewButtonUpEvent; e.PushInput(previewButtonUp, e.StagingItem); } } } // Deactivate if ((buttonInput.Actions & RawButtonActions.Deactivate) == RawButtonActions.Deactivate) { if (_isActive) { _isActive = false; // Even if handled, a button deactivate results in a lost focus. ChangeFocus(null, e.StagingItem.Input.Timestamp); } } } }