Stay organized with collections
Save and categorize content based on your preferences.
blockly > ShortcutRegistry
ShortcutRegistry class
Class for the registry of keyboard shortcuts. This is intended to be a singleton. You should not create a new instance, and only access this class from ShortcutRegistry.registry.
Signature:
export declare class ShortcutRegistry
Properties
Methods
Method |
Modifiers |
Description |
addKeyMapping(keyCode, shortcutName, allowCollision) |
|
Adds a mapping between a keycode and a keyboard shortcut. Normally only one shortcut can be mapped to any given keycode, but setting allowCollisions to true allows a keyboard to be mapped to multiple shortcuts. In that case, when onKeyDown is called with the given keystroke, it will process the mapped shortcuts in reverse order, from the most- to least-recently mapped). |
createSerializedKey(keyCode, modifiers) |
|
Creates the serialized key code that will be used in the key map. |
getKeyCodesByShortcutName(shortcutName) |
|
Gets the serialized key codes that the shortcut with the given name is registered under. |
getKeyMap() |
|
Gets the current key map. |
getRegistry() |
|
Gets the registry of keyboard shortcuts. |
getShortcutNamesByKeyCode(keyCode) |
|
Gets the shortcuts registered to the given key code. |
onKeyDown(workspace, e) |
|
Handles key down events. - Any KeyboardShortcut (s) mapped to the keycodes that cause event e to be fired will be processed, in order from least- to most-recently registered. - If the shortcut's preconditionFn exists it will be called. If preconditionFn returns false the shortcut's callback function will be skipped. Processing will continue with the next shortcut, if any. - The shortcut's callback function will then be called. If it returns true, processing will terminate and onKeyDown will return true. If it returns false, processing will continue with with the next shortcut, if any. - If all registered shortcuts for the given keycode have been processed without any having returned true, onKeyDown will return false. |
register(shortcut, allowOverrides) |
|
Registers a keyboard shortcut. |
removeAllKeyMappings(shortcutName) |
|
Removes all the key mappings for a shortcut with the given name. Useful when changing the default key mappings and the key codes registered to the shortcut are unknown. |
removeKeyMapping(keyCode, shortcutName, quiet) |
|
Removes a mapping between a keycode and a keyboard shortcut. |
reset() |
|
Clear and recreate the registry and keyMap. |
setKeyMap(newKeyMap) |
|
Sets the key map. Setting the key map will override any default key mappings. |
unregister(shortcutName) |
|
Unregisters a keyboard shortcut registered with the given name. This will also remove any key mappings that reference this shortcut. |
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 `ShortcutRegistry` class manages keyboard shortcuts in Blockly and is designed as a singleton accessed via `ShortcutRegistry.registry`."],["It provides methods to add, remove, and modify key mappings between keycodes and shortcut names."],["Developers can register, unregister, and customize keyboard shortcuts for specific actions within Blockly."],["The class maintains a key map to track registered shortcuts and their associated keycodes, offering methods for retrieval and manipulation."],["It handles key down events, enabling the execution of associated actions based on user input."]]],[]]