Skip to content

KeyboardCommand

A keyboard command shown in a modal’s control strip and optionally bound to a modifier+key handler.

Import:

import type { KeyboardCommand } from 'obsidian-dev-utils/obsidian/modals/modal-command-builder';

Signature:

export interface KeyboardCommand extends CommandBase

Extends: CommandBase

Properties

PropertyTypeDescription
keystringThe key that activates the command.
(Inherited from CommandBase)
modifiers?Modifier[]The modifiers combined with CommandBase.key. When omitted, no modifiers are required.
(Inherited from CommandBase)
purposestringThe human-readable description shown next to the control.
(Inherited from CommandBase)

Methods

MethodReturnsDescription
checkIsAvailable(this)booleanWhether the control can be used right now. When it returns false the control is rendered **disabled rather than removed**, so the strip does not reflow under the pointer as modes change — which on a phone means a mis-tap.

Re-read by ModalCommands.refresh. When omitted, the builder never touches the control's disabled state, leaving whatever CheckboxCommand.onInit / DropDownCommand.onInit set.
(Inherited from CommandBase)
checkIsOn(this)booleanWhether the command reads as ON. Supply it for a toggle whose state lives outside the strip; omit it for an action, which does something and is done. A CheckboxCommand needs no equivalent — its checkbox element is the state.

Re-read by ModalCommands.refresh.
onActivate(this, $event)voidThe pointer route into the same handler the shortcut runs. Required for the command to render a button in ModalCommandsRenderMode.Buttons mode — on a phone there is no modifier key to press, so this is the only way in.
onKey($event, context)booleanThe handler invoked when the shortcut is pressed. When omitted, the command is a hint only and no scope handler is registered.