> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cskn.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Keyboard shortcuts

> Bind shortcuts with useShortcut and show them the way each platform writes them.

Desktop users expect ⌘N for "new", ⌘F for "find" and Delete for "remove". @cskn/ui has a small set of helpers that read `mod` as ⌘ on a Mac (and on an iPad keyboard) and Ctrl everywhere else, so one binding works on both.

## useShortcut

Binds a shortcut for as long as the component is mounted.

```tsx theme={null}
import { useShortcut } from '@cskn/ui';

useShortcut('mod+n', newNote);                  // ⌘N / Ctrl+N
useShortcut('mod+shift+e', exportAll);
useShortcut('escape', close, { enabled: open });
```

**combo** `string` *required*

Modifiers and a key joined with `+`: `mod`, `shift`, `alt`, then the key, such as `n`, `escape`, `arrowup`, `space` or `delete`. `delete` matches the key a keyboard labels Delete: ⌫ on a Mac, Del or Backspace elsewhere.

**handler** `(e: KeyboardEvent) =\> boolean | void` *required*

Runs on the key. Return `false` to decline it, for example when the screen is covered, and leave it to others.

**options.enabled** `boolean` (default: true)

Turn the binding off without unmounting.

* A shortcut without a modifier doesn't fire while the user is typing in a field. Escape is the exception.
* A shortcut with a modifier fires everywhere.
* A handled key's default action is prevented.

In the desktop shell on macOS, a shortcut you list in the [app menu](https://docs.cskn.dev/sdk/native/app-control.md#menu-bar) belongs to the menu. Handle it there and bind it with `useShortcut` only for the browser.

## Showing shortcuts

`formatShortcut(combo)` writes a combination the way the platform does, for menus and tooltips:

```ts theme={null}
import { formatShortcut } from '@cskn/ui';

formatShortcut('mod+shift+n'); // "⌘⇧N" on a Mac, "Ctrl+Shift+N" elsewhere
formatShortcut('delete');      // "⌫" on a Mac, "Del" elsewhere
```

[`ContextMenu`](https://docs.cskn.dev/ui/components/overlays#contextmenu) items take `shortcut` to show such a hint, and `keys` to run the item when its element has keyboard focus.

`matchesShortcut(event, combo)` checks a keyboard event against a combination in your own handlers, and `isMacKeyboard()` tells you which modifier `mod` means.

## Built-in keys

The kit already handles these, so don't bind them yourself:

| Key | Where | Does |
| - | - | - |
| Esc | Sheets, dialogs, menus, search | Close the top one |
| ⌘\[ / Alt+←, Back key, mouse back | `StackNavigator` | Back one screen |
| ⌘F / Ctrl+F | `StackScreen` with `search` | Focus the search field |
| ⌘Z / Ctrl+Z | Outside text fields | Undo the newest undo toast |
| ↑ ↓ Home End, Enter | Stack screens | Move between rows, open one |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.