Skip to content

Keymap

Official

Manages keymap lifecycle for different obsidian#Scopes.

Import:

import { Keymap } from 'obsidian';

Signature:

export class Keymap

Constructor

new Keymap()

Constructor.

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

Properties

PropertyTypeDescription
modifiersstringThe compiled, sorted, comma-joined string of currently-pressed modifiers (e.g. 'Ctrl,Shift').
rootScopeScopeThe root scope, active when no other scope is pushed.
windowScopesWeakMap<Window, KeymapWindowStack>Per-window scope stacks, keyed by the window the events originate from.

Methods

MethodReturnsDescription
getRootScope()ScopeGets the root scope.
getWindowStack(win)KeymapWindowStackGets the scope stack for a window, creating it lazily if absent.
hasModifier(modifier)booleanChecks whether a modifier is currently pressed.
isModEvent(evt?)PaneType | booleanTranslates an event into the type of pane that should open. Returns 'tab' if the modifier key Cmd/Ctrl is pressed OR if this is a middle-click MouseEvent. Returns 'split' if Cmd/Ctrl+Alt is pressed. Returns 'window' if Cmd/Ctrl+Alt+Shift is pressed.
isModifier(evt, modifier)booleanChecks whether the modifier key is pressed during this event.
matchModifiers(modifiers)booleanChecks whether the currently-pressed modifiers exactly match the given compiled modifier string.
onFocusIn(evt)voidHandles a focus-in event for the keymap's tab-focus handling.
onKeyEvent(evt)false | voidHandles a key event, dispatching it to the active scope.
popScope(scope)voidRemove a scope from the scope stack. If the given scope is active, the next scope in the stack will be made active.
pushScope(scope)voidPush a scope onto the scope stack, setting it as the active scope to handle all key events.
registerWindow(win)() => voidRegisters keyboard and focus event listeners on a window.
setWindowBaseScope(win, scope)voidSets the base scope for a window's scope stack.
updateModifiers(evt)voidUpdates the currently-pressed modifiers from a keyboard event.

Links to this page: