Skip to content

PlatformHotkeys

ts
type PlatformHotkeys<T> = PlatformEntries<T> & object;

Defined in: hotkey.types.ts:295

A hotkey object, for a shortcut that follows each platform's convention or has more than one hotkey.

default is the hotkey. mac, windows, and linux replace it on that platform. null leaves a platform without a hotkey, and a default of null leaves every platform you don't name without one. The entry is chosen by the same platform that resolves Mod: the platform option, then a provider's, then detection. Each entry is a chord or a sequence, so an array inside is still a sequence.

alternates lists more hotkeys that fire the same callback. Each is a chord, a sequence, or an object with a default and platforms, resolved the same way. An array in the list is a sequence: ['G', 'P'] is two alternates and [['G', 'P']] is one. Labels show the first hotkey, not the alternates.

Type Parameters

T

T = RegisterableChordOrSequence

Type Declaration

alternates?

ts
optional alternates?: ReadonlyArray<HotkeyAlternate<T>>;

Example

ts
useHotkey({ default: 'Mod+Y', mac: 'Mod+Shift+Z' }, redo)
useHotkey({ default: null, mac: 'Mod+,' }, openPreferences)
useHotkey({ default: 'Space', alternates: ['K', 'MediaPlayPause'] }, togglePlay)
useHotkey(
  {
    default: 'Mod+Y',
    mac: 'Mod+Shift+Z',
    alternates: [{ default: 'Mod+Shift+Z', mac: null }],
  },
  redo,
)