public readonly record struct DesktopShortcut : IEquatable<DesktopShortcut> A keyboard shortcut: a key and its modifiers, written as Primary+Shift+S.
Remarks
matchesShortcut and formatShortcut in @runic-artifex/views read the same text with the same rule for the page, so a shortcut declared once works on the menu item and in the frontend. The default value is no shortcut: its DesktopShortcut.Key is empty and it formats as empty text; a menu item without a shortcut uses null.
Constructors
DesktopShortcut
public DesktopShortcut(string key, DesktopShortcutModifiers modifiers = DesktopShortcutModifiers.Primary) Creates a shortcut, checking and normalizing the key.
Parameters
keyThe key: a letter or digit, one of
F1toF24,Enter,Escape,Tab,Space,Backspace,Delete,ArrowUp,ArrowDown,ArrowLeft,ArrowRight,Home,End,PageUp,PageDown,Plus, or one punctuation character such as,or/. Letters are stored upper-case.modifiersThe modifiers;
DesktopShortcutModifiers.Primaryby default.
Exceptions
ArgumentExceptionThe key is not one of the supported keys.
Properties
Key
public string Key { get; } Gets the normalized key; empty for the default value.
Methods
Parse
public static DesktopShortcut Parse(string text) Reads a shortcut such as Primary+Shift+S, Alt+F4 or Primary+,.
Exceptions
FormatExceptionThe text is not a shortcut.
ToDisplayString
public string ToDisplayString() Gets the shortcut as the platform shows it: ⇧⌘S on macOS, Ctrl+Shift+S elsewhere.
ToDisplayString
public string ToDisplayString(bool macOS) Gets the shortcut as macOS (⇧⌘S) or Windows and Linux (Ctrl+Shift+S) show it.
Parameters
macOSWhether to use the macOS symbols and order.
ToString
public override string ToString() Gets the shortcut as text that DesktopShortcut.Parse reads, such as Primary+Shift+S.
TryParse
public static bool TryParse(string? text, out DesktopShortcut shortcut) Reads a shortcut, returning whether the text is one.