Application.Keyboard.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #nullable disable
  2. #nullable enable
  3. namespace Terminal.Gui.App;
  4. public static partial class Application // Keyboard handling
  5. {
  6. /// <inheritdoc cref="IApplication.Keyboard"/>
  7. public static IKeyboard Keyboard
  8. {
  9. get => ApplicationImpl.Instance.Keyboard;
  10. set => ApplicationImpl.Instance.Keyboard = value ??
  11. throw new ArgumentNullException(nameof(value));
  12. }
  13. /// <inheritdoc cref="IKeyboard.RaiseKeyDownEvent"/>
  14. public static bool RaiseKeyDownEvent (Key key) => ApplicationImpl.Instance.Keyboard.RaiseKeyDownEvent (key);
  15. /// <inheritdoc cref="IKeyboard.InvokeCommandsBoundToKey"/>
  16. public static bool? InvokeCommandsBoundToKey (Key key) => ApplicationImpl.Instance.Keyboard.InvokeCommandsBoundToKey (key);
  17. /// <inheritdoc cref="IKeyboard.InvokeCommand"/>
  18. public static bool? InvokeCommand (Command command, Key key, KeyBinding binding) => ApplicationImpl.Instance.Keyboard.InvokeCommand (command, key, binding);
  19. /// <summary>
  20. /// Raised when the user presses a key.
  21. /// <para>
  22. /// Set <see cref="Key.Handled"/> to <see langword="true"/> to indicate the key was handled and to prevent
  23. /// additional processing.
  24. /// </para>
  25. /// </summary>
  26. /// <remarks>
  27. /// All drivers support firing the <see cref="KeyDown"/> event. Some drivers (Unix) do not support firing the
  28. /// <see cref="KeyDown"/> and <see cref="KeyUp"/> events.
  29. /// <para>Fired after <see cref="KeyDown"/> and before <see cref="KeyUp"/>.</para>
  30. /// </remarks>
  31. public static event EventHandler<Key>? KeyDown
  32. {
  33. add => ApplicationImpl.Instance.Keyboard.KeyDown += value;
  34. remove => ApplicationImpl.Instance.Keyboard.KeyDown -= value;
  35. }
  36. /// <inheritdoc cref="IKeyboard.RaiseKeyUpEvent"/>
  37. public static bool RaiseKeyUpEvent (Key key) => ApplicationImpl.Instance.Keyboard.RaiseKeyUpEvent (key);
  38. /// <inheritdoc cref="IKeyboard.KeyBindings"/>
  39. public static KeyBindings KeyBindings => ApplicationImpl.Instance.Keyboard.KeyBindings;
  40. }