public bool ProcessRawEvent(RawKeyboardEventArgs rawEvent) { if (rawEvent.KeyStates == KeyStates.Down) { downKeys.Add(rawEvent.Key); } else { downKeys.Remove(rawEvent.Key); } RoutedEvent previewRoutedEvent; RoutedEvent routedEvent; if (rawEvent.KeyStates == KeyStates.Down) { previewRoutedEvent = Keyboard.PreviewKeyDownEvent; routedEvent = Keyboard.KeyDownEvent; } else if (rawEvent.KeyStates == KeyStates.None) { previewRoutedEvent = Keyboard.PreviewKeyUpEvent; routedEvent = Keyboard.KeyUpEvent; } else { throw new Granular.Exception("Unexpected KeyStates \"{0}\"", rawEvent.KeyStates); } KeyEventArgs previewEventArgs = new KeyEventArgs(previewRoutedEvent, Target, this, rawEvent.Timestamp, rawEvent.Key, rawEvent.KeyStates, rawEvent.IsRepeat); KeyEventArgs eventArgs = new KeyEventArgs(routedEvent, Target, this, rawEvent.Timestamp, rawEvent.Key, rawEvent.KeyStates, rawEvent.IsRepeat); PreProcessKey.Raise(this, previewEventArgs); if (Target != null) { Target.RaiseEvents(previewEventArgs, eventArgs); } PostProcessKey.Raise(this, eventArgs); return((previewEventArgs.Handled || eventArgs.Handled) && !previewEventArgs.ForceHostHandling && !eventArgs.ForceHostHandling); }
public bool ProcessRawEvent(RawKeyboardEventArgs rawEvent) { if (rawEvent.KeyStates == KeyStates.Down) { downKeys.Add(rawEvent.Key); } else { downKeys.Remove(rawEvent.Key); } RoutedEvent previewRoutedEvent; RoutedEvent routedEvent; if (rawEvent.KeyStates == KeyStates.Down) { previewRoutedEvent = Keyboard.PreviewKeyDownEvent; routedEvent = Keyboard.KeyDownEvent; } else if (rawEvent.KeyStates == KeyStates.None) { previewRoutedEvent = Keyboard.PreviewKeyUpEvent; routedEvent = Keyboard.KeyUpEvent; } else { throw new Granular.Exception("Unexpected KeyStates \"{0}\"", rawEvent.KeyStates); } KeyEventArgs previewEventArgs = new KeyEventArgs(previewRoutedEvent, Target, this, rawEvent.Timestamp, rawEvent.Key, rawEvent.KeyStates, rawEvent.IsRepeat); KeyEventArgs eventArgs = new KeyEventArgs(routedEvent, Target, this, rawEvent.Timestamp, rawEvent.Key, rawEvent.KeyStates, rawEvent.IsRepeat); PreProcessKey.Raise(this, previewEventArgs); if (Target != null) { Target.RaiseEvents(previewEventArgs, eventArgs); } PostProcessKey.Raise(this, eventArgs); return (previewEventArgs.Handled || eventArgs.Handled) && !previewEventArgs.ForceHostHandling && !eventArgs.ForceHostHandling; }