# FShortcut

- Human documentation: [https://docs.univer.ai/reference/facade/shortcut](https://docs.univer.ai/reference/facade/shortcut)

- Agent Markdown: [https://docs.univer.ai/reference/facade/shortcut.md](https://docs.univer.ai/reference/facade/shortcut.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/shortcut.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/shortcut.mdx)

---

The Facade API object to handle shortcuts in Univer

## Access

Access through:

* [`FUniver.getShortcut()`](https://docs.univer.ai/reference/facade/univer.md#getshortcut)

## Setup

Register [`@univerjs/ui`](https://docs.univer.ai/reference/packages/plugins/univerjs/ui.md) or a preset that includes it. In plugin mode, import `@univerjs/ui/facade`. Additional methods below require their listed plugin packages. See [Facade setup](https://docs.univer.ai/guides/sheets/getting-started/facade.md).

## `@univerjs/ui`

### `FShortcut.disableShortcut`

Disable shortcuts of Univer.

```typescript
disableShortcut(): this
```

**Returns**

The Facade API instance itself for chaining.

**Examples**

```ts
const fShortcut = univerAPI.getShortcut()
fShortcut.disableShortcut()
```

**Package:** [`@univerjs/ui`](https://docs.univer.ai/reference/packages/plugins/univerjs/ui.md) · [Type definitions](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/facade/f-shortcut.d.ts)

### `FShortcut.dispatchShortcutEvent`

Dispatch a KeyboardEvent to the shortcut service and return the matched shortcut item.

```typescript
dispatchShortcutEvent(e: KeyboardEvent): IShortcutItem<object> | undefined
```

**Parameters**

* `e` — Required. The KeyboardEvent to dispatch.

**Returns**

The matched shortcut item.

**Examples**

```ts
const fShortcut = univerAPI.getShortcut()
const pseudoEvent = new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
const ifShortcutItem = fShortcut.dispatchShortcutEvent(pseudoEvent)
if (ifShortcutItem) {
  const commandId = ifShortcutItem.id
  // Do something with the commandId.
}
```

**Types:** [`IShortcutItem`](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/services/shortcut/shortcut.service.d.ts) · [`KeyboardEvent`](https://unpkg.com/@typescript/typescript-darwin-arm64@7.0.2/lib/lib.dom.d.ts)

**Package:** [`@univerjs/ui`](https://docs.univer.ai/reference/packages/plugins/univerjs/ui.md) · [Type definitions](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/facade/f-shortcut.d.ts)

### `FShortcut.enableShortcut`

Enable shortcuts of Univer.

```typescript
enableShortcut(): this
```

**Returns**

The Facade API instance itself for chaining.

**Examples**

```ts
fShortcut.enableShortcut() // Use the FShortcut instance used by disableShortcut before, do not create a new instance
```

**Package:** [`@univerjs/ui`](https://docs.univer.ai/reference/packages/plugins/univerjs/ui.md) · [Type definitions](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/facade/f-shortcut.d.ts)

### `FShortcut.triggerShortcut`

Trigger shortcut of Univer by a KeyboardEvent and return the matched shortcut item.

```typescript
triggerShortcut(e: KeyboardEvent): IShortcutItem<object> | undefined
```

**Parameters**

* `e` — Required. The KeyboardEvent to trigger.

**Returns**

The matched shortcut item.

**Examples**

```ts
// Assum the current sheet is empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fRange = fWorksheet.getRange('A1')

// Set A1 cell active and set value to 'Hello Univer'.
fRange.activate()
fRange.setValue('Hello Univer')
console.log(fRange.getCellStyle().bold) // false

// Set A1 cell bold by shortcut.
const fShortcut = univerAPI.getShortcut()
const pseudoEvent = new KeyboardEvent('keydown', {
  key: 'b',
  ctrlKey: true,
  keyCode: univerAPI.Enum.KeyCode.B,
})
const ifShortcutItem = fShortcut.triggerShortcut(pseudoEvent)
if (ifShortcutItem) {
  const commandId = ifShortcutItem.id
  console.log(fRange.getCellStyle().bold) // true
}
```

**Types:** [`IShortcutItem`](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/services/shortcut/shortcut.service.d.ts) · [`KeyboardEvent`](https://unpkg.com/@typescript/typescript-darwin-arm64@7.0.2/lib/lib.dom.d.ts)

**Package:** [`@univerjs/ui`](https://docs.univer.ai/reference/packages/plugins/univerjs/ui.md) · [Type definitions](https://unpkg.com/@univerjs/ui@1.0.0-rc.0/lib/types/facade/f-shortcut.d.ts)
