# useShortcut

True on Apple platforms, where "mod" is ⌘ rather than Ctrl.

- Registry name: `use-shortcut` (`@candor/use-shortcut`)
- Tier: Free (MIT). No licence key needed.
- Docs: https://candor.themethodic.com/docs/use-shortcut

## Install

```bash
npx candor-ui add use-shortcut
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/use-shortcut`.

## Example

```tsx
"use client"

import * as React from "react"
import { comboKeys, useShortcut } from "@/lib/use-shortcut"
import { Kbd, KbdGroup } from "@/components/ui/kbd"

export default function Example() {
  const [count, setCount] = React.useState(0)
  useShortcut("mod+j", () => setCount((n) => n + 1))
  return (
    <p className="flex items-center gap-2 text-sm">
      Press
      <KbdGroup>
        {comboKeys("mod+j").map((k) => (
          <Kbd key={k}>{k}</Kbd>
        ))}
      </KbdGroup>
      — pressed {count} {count === 1 ? "time" : "times"}.
    </p>
  )
}
```

## Functions

### isApple

```ts
isApple()
```

True on Apple platforms, where "mod" is ⌘ rather than Ctrl.

### comboKeys

```ts
comboKeys(combo: string)
```

The keys of a combo as they should be printed: "mod+k" → ["⌘", "K"] on a Mac and ["Ctrl", "K"] elsewhere.

### useShortcut

```ts
useShortcut(combo: string, handler: (e: KeyboardEvent) => void, { enabled = true }: { enabled?: boolean | undefined } = {})
```

Run `handler` when a key combo is pressed anywhere on the page: "mod+k", "mod+shift+o", "?", "escape". A combo without mod or alt is ignored while the person is typing in a field, so "?" still types a question mark.

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
