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.
[null,null,["Last updated 2025-05-16 UTC."],[],["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"]]