DesktopShortcut record struct

Namespace Runic.Platform in Runic.Platform 0.23.0

public readonly record struct DesktopShortcut : IEquatable<DesktopShortcut>

Inherits or implements IEquatable.

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

key

The key: a letter or digit, one of F1 to F24, 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.

modifiers

The modifiers; DesktopShortcutModifiers.Primary by default.

Exceptions

ArgumentException

The key is not one of the supported keys.

Properties

Key

public string Key { get; }

Gets the normalized key; empty for the default value.

Modifiers

public DesktopShortcutModifiers Modifiers { get; }

Gets the modifiers.

Methods

Parse

public static DesktopShortcut Parse(string text)

Reads a shortcut such as Primary+Shift+S, Alt+F4 or Primary+,.

Exceptions

FormatException

The 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

macOS

Whether 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.