Skip to content
GitHub11 stars

Runs an action when a key is pressed with Ctrl or ⌘ anywhere on the page.

Press Ctrl+M (⌘M on macOS). Pressed 0 times.

<KeyboardShortcut Key="m" OnPressed="() => _count++" />
<p class="keyboard-shortcut-text">
    Press <kbd class="keyboard-shortcut-key">Ctrl</kbd>+<kbd class="keyboard-shortcut-key">M</kbd> (<kbd class="keyboard-shortcut-key">⌘</kbd><kbd class="keyboard-shortcut-key">M</kbd> on macOS).
    Pressed <strong>@_count</strong> times.
</p>

@code {
    private int _count;
}

KeyboardShortcut is the sidebar's Ctrl+B shortcut on its own. It listens on the whole page, stops the browser's own handling of the keys by default, and renders nothing.

Anatomy

@using Blazix.Primitives

<KeyboardShortcut Key="b" OnPressed="ToggleSidebar" />

API Reference

KeyboardShortcut

Doesn't render its own HTML element.

ParameterTypeDefault
Keyrequired string -
CtrlOrMeta bool true
Shift bool false
Alt bool false
PreventDefault bool true
OnPressed EventCallback -