Référence de l’API

FShortcut

Cette page API est actuellement disponible en anglais. Les signatures et identifiants restent identiques dans toutes les langues.

The Facade API object to handle shortcuts in Univer

Access

Access through:

Setup

Register @univerjs/ui or a preset that includes it. In plugin mode, import @univerjs/ui/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs/ui

FShortcut.disableShortcut

Disable shortcuts of Univer.

TypeScript
disableShortcut(): this

Returns

The Facade API instance itself for chaining.

Examples

TypeScript
const fShortcut = univerAPI.getShortcut()fShortcut.disableShortcut()

Package: @univerjs/ui · Type definitions

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

TypeScript
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 · KeyboardEvent

Package: @univerjs/ui · Type definitions

FShortcut.enableShortcut

Enable shortcuts of Univer.

TypeScript
enableShortcut(): this

Returns

The Facade API instance itself for chaining.

Examples

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

Package: @univerjs/ui · Type definitions

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

TypeScript
// 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 · KeyboardEvent

Package: @univerjs/ui · Type definitions

Que pensez-vous de ce guide ?

© 2026 DreamNum Co., Ltd.