Skip to main content

Interface: KeyboardShortcut

Defined in: packages/blockly/core/shortcut_registry.ts:379

Interface defining a keyboard shortcut.

Properties index

PropertyDescription
callbackThe function to be called when the shorctut is invoked.
nameThe name of the shortcut. Should be unique.
preconditionFnA function to be called when the shortcut is invoked, before calling callback, to decide if this shortcut is applicable in the current situation.
metadataOptional arbitray extra data attached to the shortcut.
keyCodesOptional list of key codes to be bound (via ShortcutRegistry.prototype.addKeyMapping) to this shortcut.
allowCollisionValue of allowCollision to pass to addKeyMapping when binding this shortcut's .keyCodes (if any).
displayTextDisplay text for the shortcut. This is not used in core but may be used by plugins or applications to provide a user-facing label for the shortcut.

Properties

callback?

optional callback?: (workspace, e, shortcut, scope) => boolean;

Defined in: packages/blockly/core/shortcut_registry.ts:395

The function to be called when the shorctut is invoked.

Parameters

ParameterTypeDescription
workspaceWorkspaceSvgThe WorkspaceSvg when the shortcut was invoked.
eEventThe event that caused the shortcut to be activated.
shortcutKeyboardShortcutThe KeyboardShortcut that was activated (i.e., the one this callback is attached to).
scopeScopeInformation about the focused item when the shortcut was invoked.

Returns

boolean

Returning true ends processing of the invoked keycode. Returning false causes processing to continue with the next-most-recently registered shortcut for the invoked keycode.


name

name: string;

Defined in: packages/blockly/core/shortcut_registry.ts:403

The name of the shortcut. Should be unique.


preconditionFn?

optional preconditionFn?: (workspace, scope) => boolean;

Defined in: packages/blockly/core/shortcut_registry.ts:416

A function to be called when the shortcut is invoked, before calling callback, to decide if this shortcut is applicable in the current situation.

Parameters

ParameterTypeDescription
workspaceWorkspaceSvgThe WorkspaceSvg where the shortcut was invoked.
scopeScopeInformation about the focused item when the shortcut would be invoked.

Returns

boolean

True iff callback function should be called.


metadata?

optional metadata?: object;

Defined in: packages/blockly/core/shortcut_registry.ts:419

Optional arbitray extra data attached to the shortcut.


keyCodes?

optional keyCodes?: (string | number)[];

Defined in: packages/blockly/core/shortcut_registry.ts:425

Optional list of key codes to be bound (via ShortcutRegistry.prototype.addKeyMapping) to this shortcut.


allowCollision?

optional allowCollision?: boolean;

Defined in: packages/blockly/core/shortcut_registry.ts:436

Value of allowCollision to pass to addKeyMapping when binding this shortcut's .keyCodes (if any).

N.B.: this is only used for binding keycodes at the time this shortcut is initially registered, not for any subsequent addKeyMapping calls that happen to reference this shortcut's name.


displayText?

optional displayText?: string | (() => string);

Defined in: packages/blockly/core/shortcut_registry.ts:443

Display text for the shortcut. This is not used in core but may be used by plugins or applications to provide a user-facing label for the shortcut.