private static void WindowPreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F12) { var window = (Window)sender; var devToolsWindow = default(Window); if (s_open.TryGetValue(window, out devToolsWindow)) { devToolsWindow.Activate(); } else { devToolsWindow = new Window { Width = 1024, Height = 512, Content = new DevTools(window), DataTemplates = new DataTemplates { new ViewLocator<ReactiveObject>(), } }; devToolsWindow.Closed += DevToolsClosed; s_open.Add((Window)sender, devToolsWindow); devToolsWindow.Show(); } } }
private static void WindowPreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F12) { Window window = new Window { Width = 1024, Height = 512, Content = new DevTools { Root = (Window)sender, }, }; window.Show(); } }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (!e.Handled) { if (e.Key == Key.F4 || (e.Key == Key.Down && ((e.Modifiers & ModifierKeys.Alt) != 0))) { IsDropDownOpen = !IsDropDownOpen; e.Handled = true; } else if (IsDropDownOpen && (e.Key == Key.Escape || e.Key == Key.Enter)) { IsDropDownOpen = false; e.Handled = true; } } }
/// <inheritdoc/> protected override void OnKeyDown(KeyEventArgs e) { if (!e.Handled) { switch (e.Key) { case Key.Right: if (Items != null && Items.Cast<object>().Any()) { IsExpanded = true; } e.Handled = true; break; case Key.Left: IsExpanded = false; e.Handled = true; break; } } base.OnKeyDown(e); }
/// <summary> /// Called when a key is pressed within the menu. /// </summary> /// <param name="e">The event args.</param> protected override void OnKeyDown(KeyEventArgs e) { bool menuWasOpen = SelectedMenuItem?.IsSubMenuOpen ?? false; base.OnKeyDown(e); if (menuWasOpen) { // If a menu item was open and we navigate to a new one with the arrow keys, open // that menu and select the first item. var selection = SelectedMenuItem; if (selection != null && !selection.IsSubMenuOpen) { selection.IsSubMenuOpen = true; selection.SelectedIndex = 0; } } }
private void ProcessRawEvent(RawInputEventArgs e) { IInputElement element = FocusedElement; if (element != null) { var keyInput = e as RawKeyEventArgs; if (keyInput != null) { switch (keyInput.Type) { case RawKeyEventType.KeyDown: case RawKeyEventType.KeyUp: var routedEvent = keyInput.Type == RawKeyEventType.KeyDown ? InputElement.KeyDownEvent : InputElement.KeyUpEvent; KeyEventArgs ev = new KeyEventArgs { RoutedEvent = routedEvent, Device = this, Key = keyInput.Key, Modifiers = keyInput.Modifiers, Source = element, }; IVisual currentHandler = element; while (currentHandler != null && !ev.Handled && keyInput.Type == RawKeyEventType.KeyDown) { var bindings = (currentHandler as IInputElement)?.KeyBindings; if(bindings!=null) foreach (var binding in bindings) { if(ev.Handled) break; binding.TryHandle(ev); } currentHandler = currentHandler.VisualParent; } element.RaiseEvent(ev); break; } } var text = e as RawTextInputEventArgs; if (text != null) { element.RaiseEvent(new TextInputEventArgs() { Device = this, Text = text.Text, Source = element, RoutedEvent = InputElement.TextInputEvent }); } } }
/// <summary> /// Called before the <see cref="KeyDown"/> event occurs. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnKeyDown(KeyEventArgs e) { }
protected override void OnKeyDown(KeyEventArgs e) { // Don't handle keypresses. }
/// <summary> /// Called when a key is pressed in the owner window. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.LeftAlt) { if (this.MainMenu == null || !this.MainMenu.IsOpen) { // When Alt is pressed without a main menu, or with a closed main menu, show // access key markers in the window (i.e. "_File"). this.owner.ShowAccessKeys = this.showingAccessKeys = true; } else { // If the Alt key is pressed and the main menu is open, close the main menu. this.CloseMenu(); this.ignoreAltUp = true; } // We always handle the Alt key. e.Handled = true; } }
private void ProcessRawEvent(RawKeyEventArgs e) { IInputElement element = this.FocusedElement; if (element != null) { switch (e.Type) { case RawKeyEventType.KeyDown: case RawKeyEventType.KeyUp: var routedEvent = e.Type == RawKeyEventType.KeyDown ? InputElement.KeyDownEvent : InputElement.KeyUpEvent; KeyEventArgs ev = new KeyEventArgs { RoutedEvent = routedEvent, Device = this, Key = e.Key, Text = e.Text, Source = element, OriginalSource = element, }; element.RaiseEvent(ev); break; } } }
/// <summary> /// Handles the Tab key being pressed in the window. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnKeyDown(object sender, KeyEventArgs e) { var current = FocusManager.Instance.Current; if (e.Key == Key.Tab && current != null) { if ((KeyboardDevice.Instance.Modifiers & ModifierKeys.Shift) == 0) { this.TabNext(current); } else { this.TabPrevious(current); } } }
/// <summary> /// Handles the Tab key being pressed in the window. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnKeyDown(object sender, KeyEventArgs e) { var current = FocusManager.Instance.Current; if (current != null) { FocusNavigationDirection? direction = null; switch (e.Key) { case Key.Tab: direction = (e.Modifiers & ModifierKeys.Shift) == 0 ? FocusNavigationDirection.Next : FocusNavigationDirection.Previous; break; case Key.Up: direction = FocusNavigationDirection.Up; break; case Key.Down: direction = FocusNavigationDirection.Down; break; case Key.Left: direction = FocusNavigationDirection.Left; break; case Key.Right: direction = FocusNavigationDirection.Right; break; } if (direction.HasValue) { Move(current, direction.Value); e.Handled = true; } } }
/// <summary> /// Create HtmlRenderer key event from Perspex key event. /// </summary> private static RKeyEvent CreateKeyEevent(KeyEventArgs e) { var control = (e.Modifiers & InputModifiers.Control) == InputModifiers.Control; return new RKeyEvent(control, e.Key == Key.A, e.Key == Key.C); }
/// <summary> /// Handle key down event for selection and copy. /// </summary> /// <param name="parent">the control hosting the html to invalidate</param> /// <param name="e">the pressed key</param> public void HandleKeyDown(Control parent, KeyEventArgs e) { ArgChecker.AssertArgNotNull(parent, "parent"); ArgChecker.AssertArgNotNull(e, "e"); _htmlContainerInt.HandleKeyDown(new ControlAdapter(parent), CreateKeyEevent(e)); }
/// <inheritdoc/> protected override void OnKeyDown(KeyEventArgs e) { // Ignore key presses. }
/// <summary> /// Called when a key is pressed in the owner window. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnKeyDown(object sender, KeyEventArgs e) { bool menuIsOpen = this.MainMenu?.IsOpen == true; if (e.Key == Key.Escape && menuIsOpen) { // When the Escape key is pressed with the main menu open, close it. this.CloseMenu(); e.Handled = true; } else if ((KeyboardDevice.Instance.Modifiers & ModifierKeys.Alt) != 0 || menuIsOpen) { // If any other key is pressed with the Alt key held down, or the main menu is open, // find all controls who have registered that access key. var text = e.Text.ToUpper(); var matches = this.registered .Where(x => x.Item1 == text && x.Item2.IsEffectivelyVisible) .Select(x => x.Item2); // If the menu is open, only match controls in the menu's visual tree. if (menuIsOpen) { matches = matches.Where(x => this.MainMenu.IsVisualAncestorOf(x)); } var match = matches.FirstOrDefault(); // If there was a match, raise the AccessKeyPressed event on it. if (match != null) { match.RaiseEvent(new RoutedEventArgs(AccessKeyPressedEvent)); e.Handled = true; } } }
private void ProcessRawEvent(RawInputEventArgs e) { IInputElement element = FocusedElement; if (element != null) { var keyInput = e as RawKeyEventArgs; if (keyInput != null) { switch (keyInput.Type) { case RawKeyEventType.KeyDown: case RawKeyEventType.KeyUp: var routedEvent = keyInput.Type == RawKeyEventType.KeyDown ? InputElement.KeyDownEvent : InputElement.KeyUpEvent; KeyEventArgs ev = new KeyEventArgs { RoutedEvent = routedEvent, Device = this, Key = keyInput.Key, Modifiers = keyInput.Modifiers, Source = element, }; element.RaiseEvent(ev); break; } } var text = e as RawTextInputEventArgs; if (text != null) { element.RaiseEvent(new TextInputEventArgs() { Device = this, Text = text.Text, Source = element, RoutedEvent = InputElement.TextInputEvent }); } } }
/// <summary> /// Handles the Alt/F10 keys being released in the window. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnPreviewKeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.LeftAlt: if (this.ignoreAltUp) { this.ignoreAltUp = false; } else if (this.showingAccessKeys && this.MainMenu != null) { this.MainMenu.Open(); e.Handled = true; } break; case Key.F10: this.owner.ShowAccessKeys = this.showingAccessKeys = true; this.MainMenu.Open(); e.Handled = true; break; } }
protected override void OnKeyDown(KeyEventArgs e) { string text = this.Text ?? string.Empty; int caretIndex = this.CaretIndex; bool movement = false; bool textEntered = false; bool handled = true; var modifiers = e.Device.Modifiers; switch (e.Key) { case Key.A: if (modifiers == ModifierKeys.Control) { this.SelectAll(); } else { goto default; } break; case Key.Left: this.MoveHorizontal(-1, modifiers); movement = true; break; case Key.Right: this.MoveHorizontal(1, modifiers); movement = true; break; case Key.Up: this.MoveVertical(-1, modifiers); movement = true; break; case Key.Down: this.MoveVertical(1, modifiers); movement = true; break; case Key.Home: this.MoveHome(modifiers); movement = true; break; case Key.End: this.MoveEnd(modifiers); movement = true; break; case Key.Back: if (!this.DeleteSelection() && this.CaretIndex > 0) { this.Text = text.Substring(0, caretIndex - 1) + text.Substring(caretIndex); --this.CaretIndex; } break; case Key.Delete: if (!this.DeleteSelection() && caretIndex < text.Length) { this.Text = text.Substring(0, caretIndex) + text.Substring(caretIndex + 1); } break; case Key.Enter: if (this.AcceptsReturn) { goto default; } break; case Key.Tab: if (this.AcceptsTab) { goto default; } else { base.OnKeyDown(e); handled = false; } break; default: if (!string.IsNullOrEmpty(e.Text)) { this.DeleteSelection(); caretIndex = this.CaretIndex; text = this.Text ?? string.Empty; this.Text = text.Substring(0, caretIndex) + e.Text + text.Substring(caretIndex); ++this.CaretIndex; textEntered = true; } break; } if (movement && ((modifiers & ModifierKeys.Shift) != 0)) { this.SelectionEnd = this.CaretIndex; } else if (movement || textEntered) { this.SelectionStart = this.SelectionEnd = this.CaretIndex; } if (handled) { e.Handled = true; } }
protected override void OnKeyDown(KeyEventArgs e) { string text = Text ?? string.Empty; int caretIndex = CaretIndex; bool movement = false; bool handled = true; var modifiers = e.Modifiers; switch (e.Key) { case Key.A: if (modifiers == InputModifiers.Control) { SelectAll(); } break; case Key.C: if (modifiers == InputModifiers.Control) { Copy(); } break; case Key.V: if (modifiers == InputModifiers.Control) { Paste(); } break; case Key.Left: MoveHorizontal(-1, modifiers); movement = true; break; case Key.Right: MoveHorizontal(1, modifiers); movement = true; break; case Key.Up: MoveVertical(-1, modifiers); movement = true; break; case Key.Down: MoveVertical(1, modifiers); movement = true; break; case Key.Home: MoveHome(modifiers); movement = true; break; case Key.End: MoveEnd(modifiers); movement = true; break; case Key.Back: if (!DeleteSelection() && CaretIndex > 0) { Text = text.Substring(0, caretIndex - 1) + text.Substring(caretIndex); --CaretIndex; } break; case Key.Delete: if (!DeleteSelection() && caretIndex < text.Length) { Text = text.Substring(0, caretIndex) + text.Substring(caretIndex + 1); } break; case Key.Enter: if (AcceptsReturn) { HandleTextInput("\r\n"); } break; case Key.Tab: if (AcceptsTab) { HandleTextInput("\t"); } else { base.OnKeyDown(e); handled = false; } break; } if (movement && ((modifiers & InputModifiers.Shift) != 0)) { SelectionEnd = CaretIndex; } else if (movement) { SelectionStart = SelectionEnd = CaretIndex; } if (handled) { e.Handled = true; } }
/// <summary> /// Called when a key is pressed within the control. /// </summary> /// <param name="e">The event args.</param> protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (!e.Handled) { switch (e.Key) { case Key.Up: this.MoveSelection(FocusNavigationDirection.Up); break; case Key.Down: this.MoveSelection(FocusNavigationDirection.Down); break; case Key.Left: this.MoveSelection(FocusNavigationDirection.Left); break; case Key.Right: this.MoveSelection(FocusNavigationDirection.Right); break; default: return; } var selected = this.SelectedItem; if (selected != null) { var container = this.ItemContainerGenerator.GetContainerForItem(selected); if (container != null) { container.BringIntoView(); FocusManager.Instance.Focus(container, true); } } e.Handled = true; } }
/// <summary> /// Called before the <see cref="KeyUp"/> event occurs. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnKeyUp(KeyEventArgs e) { }
/// <summary> /// Handles a key being pressed in the menu. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> protected virtual void OnKeyDown(object sender, KeyEventArgs e) { if (!string.IsNullOrWhiteSpace(e.Text)) { var text = e.Text.ToUpper(); var focus = this.registered .Where(x => x.Item1 == text && x.Item2.IsEffectivelyVisible) .FirstOrDefault()?.Item2; if (focus != null) { focus.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent)); } e.Handled = true; } }