Blockly. ShortcutRegistry
Constructor
ShortcutRegistry
new ShortcutRegistry()
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 Blockly.ShortcutRegistry.registry.
Enumeration
modifierKeys
non-null Blockly.utils.KeyCodes containing number
Enum of valid modifiers.
Value |
|
---|---|
Shift |
|
Control |
|
Alt |
|
Meta |
Property
modifierKeys
non-null Blockly.utils.KeyCodes containing number
Enum of valid modifiers.
Value |
|
---|---|
Shift |
|
Control |
|
Alt |
|
Meta |
Methods
addKeyMapping
addKeyMapping(keyCode, shortcutName, opt_allowCollision)
Adds a mapping between a keycode and a keyboard shortcut.
Parameter |
|
---|---|
keyCode |
string The key code for the keyboard shortcut. If registering a key code with a modifier (ex: ctrl+c) use Blockly.ShortcutRegistry.registry.createSerializedKey; |
shortcutName |
string The name of the shortcut to execute when the given keycode is pressed. |
opt_allowCollision |
Optional boolean True to prevent an error when adding a shortcut to a key that is already mapped to a shortcut. |
- Throws
-
Error
if the given key code is already mapped to a shortcut.
createSerializedKey
createSerializedKey(keyCode, modifiers) returns string
Creates the serialized key code that will be used in the key map.
Parameter |
|
---|---|
keyCode |
number Number code representing the key. |
modifiers |
Array of string List of modifier key codes to be used with the key. All valid modifiers can be found in the Blockly.ShortcutRegistry.modifierKeys. Value may be null. |
- Returns
-
string
The serialized key code for the given modifiers and key.
getKeyCodesByShortcutName
getKeyCodesByShortcutName(shortcutName) returns Array of string
Gets the serialized key codes that the shortcut with the given name is registered under.
Parameter |
|
---|---|
shortcutName |
string The name of the shortcut. |
- Returns
-
non-null Array of string
An array with all the key codes the shortcut is registered under.
getKeyMap
getKeyMap() returns Object with non-null Array of non-null Blockly.ShortcutRegistry.KeyboardShortcut properties
Gets the current key map.
- Returns
-
non-null Object with non-null Array of non-null Blockly.ShortcutRegistry.KeyboardShortcut properties
The object holding key codes to Blockly.ShortcutRegistry.KeyboardShortcut.
getRegistry
getRegistry() returns Object with non-null Blockly.ShortcutRegistry.KeyboardShortcut properties
Gets the registry of keyboard shortcuts.
- Returns
-
non-null Object with non-null Blockly.ShortcutRegistry.KeyboardShortcut properties
The registry of keyboard shortcuts.
getShortcutNamesByKeyCode
getShortcutNamesByKeyCode(keyCode) returns (non-null Array of string or undefined)
Gets the shortcuts registered to the given key code.
Parameter |
|
---|---|
keyCode |
string The serialized key code. |
- Returns
-
(non-null Array of string or undefined)
The list of shortcuts to call when the given keyCode is used. Undefined if no shortcuts exist.
onKeyDown
onKeyDown(workspace, e) returns boolean
Handles key down events.
Parameter |
|
---|---|
workspace |
The main workspace where the event was captured. Value must not be null. |
e |
Event The key down event. Value must not be null. |
- Returns
-
boolean
True if the event was handled, false otherwise.
register
register(shortcut, opt_allowOverrides)
Registers a keyboard shortcut.
Parameter |
|
---|---|
shortcut |
Blockly.ShortcutRegistry.KeyboardShortcut The shortcut for this key code. Value must not be null. |
opt_allowOverrides |
Optional boolean True to prevent a warning when overriding an already registered item. |
- Throws
-
Error
if a shortcut with the same name already exists.
removeAllKeyMappings
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.
Parameter |
|
---|---|
shortcutName |
string The name of the shortcut to remove from the key map. |
removeKeyMapping
removeKeyMapping(keyCode, shortcutName, opt_quiet) returns boolean
Removes a mapping between a keycode and a keyboard shortcut.
Parameter |
|
---|---|
keyCode |
string The key code for the keyboard shortcut. If registering a key code with a modifier (ex: ctrl+c) use Blockly.ShortcutRegistry.registry.createSerializedKey; |
shortcutName |
string The name of the shortcut to execute when the given keycode is pressed. |
opt_quiet |
Optional boolean True to not console warn when there is no shortcut to remove. |
- Returns
-
boolean
True if a key mapping was removed, false otherwise.
setKeyMap
setKeyMap(keyMap)
Sets the key map. Setting the key map will override any default key mappings.
Parameter |
|
---|---|
keyMap |
Object with non-null Array of string properties The object with key code to shortcut names. Value must not be null. |
unregister
unregister(shortcutName) returns boolean
Unregisters a keyboard shortcut registered with the given key code. This will also remove any key mappings that reference this shortcut.
Parameter |
|
---|---|
shortcutName |
string The name of the shortcut to unregister. |
- Returns
-
boolean
True if an item was unregistered, false otherwise.
Abstract type
KeyboardShortcut
{callback: (function(non-null Blockly.Workspace, Event, non-null Blockly.ShortcutRegistry.KeyboardShortcut) returns boolean or undefined), name: string, preconditionFn: (function(non-null Blockly.Workspace) returns boolean or undefined), metadata: (Object or undefined)}
A keyboard shortcut.