blockly > ShortcutRegistry > addKeyMapping

ShortcutRegistry.addKeyMapping() method

Adds a mapping between a keycode and a keyboard shortcut.

Signature:

addKeyMapping(keyCode: string | number | KeyCodes, shortcutName: string, opt_allowCollision?: boolean): void;

Parameters

Parameter Type Description
keyCode string | number | KeyCodes The key code for the keyboard shortcut. If registering a key code with a modifier (ex: ctrl+c) use ShortcutRegistry.registry.createSerializedKey;
shortcutName string The name of the shortcut to execute when the given keycode is pressed.
opt_allowCollision boolean (Optional) True to prevent an error when adding a shortcut to a key that is already mapped to a shortcut.

Returns:

void

Exceptions

{Error} if the given key code is already mapped to a shortcut.