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

Property Modifiers Type Description
registry

static

readonly

ShortcutRegistry

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.