Stay organized with collections
Save and categorize content based on your preferences.
blockly > ShortcutRegistry > KeyboardShortcut
ShortcutRegistry.KeyboardShortcut interface
Interface defining a keyboard shortcut.
Signature:
interface KeyboardShortcut
Properties
Property |
Modifiers |
Type |
Description |
allowCollision? |
|
boolean |
(Optional) 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. |
callback? |
|
(workspace: WorkspaceSvg, e: Event, shortcut: KeyboardShortcut, scope: Scope) => boolean |
(Optional) The function to be called when the shorctut is invoked. |
keyCodes? |
|
(number | string)[] |
(Optional) Optional list of key codes to be bound (via ShortcutRegistry.prototype.addKeyMapping) to this shortcut. |
metadata? |
|
object |
(Optional) Optional arbitray extra data attached to the shortcut. |
name |
|
string |
The name of the shortcut. Should be unique. |
preconditionFn? |
|
(workspace: WorkspaceSvg, scope: Scope) => boolean |
(Optional) A function to be called when the shortcut is invoked, before calling callback , to decide if this shortcut is applicable in the current situation. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-16 UTC."],[[["The `KeyboardShortcut` interface defines the structure for keyboard shortcuts within Blockly's ShortcutRegistry."],["Each `KeyboardShortcut` includes properties for its name, key codes, callback function, precondition function, collision behavior, and metadata."],["Properties like `callback`, `keyCodes`, `preconditionFn`, `allowCollision`, and `metadata` are optional, allowing for flexibility in shortcut definitions."],["The `callback` function executes when the shortcut is triggered, while `preconditionFn` determines if the shortcut is applicable in the current context."],["`allowCollision` dictates if multiple shortcuts with the same key codes can be registered, while `metadata` can store additional information about the shortcut."]]],["The `KeyboardShortcut` interface defines properties for keyboard shortcuts. It includes a mandatory `name` (string) and several optional properties: `allowCollision` (boolean) to manage shortcut conflicts, `callback` (function) for the action to perform, `keyCodes` (array) specifying the keyboard input, `metadata` (object) for extra data, and `preconditionFn` (function) for a condition that must be met before the shortcut is used. The `callback` and `preconditionFn` are functions that receive a `WorkspaceSvg` object as an input.\n"]]