Application.Keyboard.cs 2.1 KB

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