Skip to content

HotkeyManager

Unofficial

Manager for keyboard shortcut registration, storage, and triggering.

Import:

import type { HotkeyManager } from '@obsidian-typings/obsidian-catalyst-latest';

Signature:

export interface HotkeyManager

Constructor

new HotkeyManager(app: App)

Constructor.

To get the constructor instance, use getHotkeyManagerConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
appAppReference to the obsidian#App.
bakedbooleanWhether hotkeys have been baked (checks completed).
bakedHotkeysKeymapInfo[]Assigned hotkeys, compiled by HotkeyManager.bake from the custom hotkeys and then the default hotkeys of every command without custom ones. Unlike the obsidian#Hotkey entries they are compiled from, their modifiers is a single string.
bakedIdsstring[]Array of hotkey index to command ID.
customKeysHotkeyManagerCustomKeysRecordCustom (non-Obsidian default) hotkeys, one to many mapping of command ID to assigned hotkey.

A getter returning a shallow copy of the stored record, so a key written on it is not persisted. Use HotkeyManager.setHotkeys and HotkeyManager.removeHotkeys instead.
defaultKeysHotkeyManagerDefaultKeysRecordDefault hotkeys, one to many mapping of command ID to assigned hotkey.
onConfigFileChangeDebouncer<[], Promise<void>>Debounced handler for hotkey config file changes on disk.

Methods

MethodReturnsDescription
addDefaultHotkeys(command, keys)voidAdd a hotkey to the default hotkeys.
bake()voidBake hotkeys (create mapping of pressed key to command ID).
getDefaultHotkeys(command)Hotkey[] | undefinedGet hotkey associated with command ID.
getHotkeys(command)Hotkey[] | undefinedGet hotkey associated with command ID.
load()Promise<void>Load the custom hotkeys from the hotkeys config file, replacing the in-memory record when the file holds an object.
onRaw(e)voidHandle raw file system change events for the hotkey config.
onTrigger($event, keypress)booleanTrigger a command by keyboard event.
printHotkeyForCommand(commandId)stringPretty-print hotkey of a command.
registerListeners()voidRegister event listeners for hotkey config file changes.
removeDefaultHotkeys(command)voidRemove a hotkey from the default hotkeys.
removeHotkeys(command)voidRemove a hotkey from the custom hotkeys.
save()Promise<void>Save the custom hotkeys to the hotkeys config file.
setHotkeys(command, keys)voidAdd a hotkey to the custom hotkeys (overrides default hotkeys).

Links to this page: