Application.Keyboard.cs 2.0 KB

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