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

Property Type Description
modifiers string The compiled, sorted, comma-joined string of currently-pressed modifiers (e.g. 'Ctrl,Shift').
rootScope Scope The root scope, active when no other scope is pushed.
windowScopes WeakMap<Window, KeymapWindowStack> Per-window scope stacks, keyed by the window the events originate from.

Methods

Method Returns Description
getRootScope() Scope Gets the root scope.
getWindowStack(win) KeymapWindowStack Gets the scope stack for a window, creating it lazily if absent.
hasModifier(modifier) boolean Checks whether a modifier is currently pressed.
isModEvent(evt?) PaneType | boolean Translates 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) boolean Checks whether the modifier key is pressed during this event.
matchModifiers(modifiers) boolean Checks whether the currently-pressed modifiers exactly match the given compiled modifier string.
onFocusIn(evt) void Handles a focus-in event for the keymap's tab-focus handling.
onKeyEvent(evt) false | void Handles a key event, dispatching it to the active scope.
popScope(scope) void Remove a scope from the scope stack. If the given scope is active, the next scope in the stack will be made active.
pushScope(scope) void Push a scope onto the scope stack, setting it as the active scope to handle all key events.
registerWindow(win) () => void Registers keyboard and focus event listeners on a window.
setWindowBaseScope(win, scope) void Sets the base scope for a window's scope stack.
updateModifiers(evt) void Updates the currently-pressed modifiers from a keyboard event.

Links to this page: