Skip to main content

KeyBindingManager

Import :

const KeyBindingManager = brackets.getModule("command/KeyBindingManager")

useWindowsCompatibleBindings

Use windows-specific bindings if no other are found (e.g. Linux). Core Brackets modules that use key bindings should always define at least a generic keybinding that is applied for all platforms. This setting effectively creates a compatibility mode for third party extensions that define explicit key bindings for Windows and Mac, but not Linux.

Kind: global variable

EVENT_KEY_BINDING_ADDED : string

key binding add event

Kind: global constant

EVENT_KEY_BINDING_REMOVED : string

key binding remove event

Kind: global constant

EVENT_NEW_PRESET : string

new preset event

Kind: global constant

EVENT_PRESET_CHANGED : string

preset change event

Kind: global constant

KEY : Object

Kind: global constant

formatKeyDescriptor(descriptor) ⇒ string

Convert normalized key representation to display appropriate for platform.

Kind: global function
Returns: string - Display/Operating system appropriate string

ParamTypeDescription
descriptorstringNormalized key descriptor.

removeBinding(key, [platform])

Remove a key binding from _keymap

Kind: global function

ParamTypeDescription
keystringa key-description string that may or may not be normalized.
[platform]stringOS from which to remove the binding (all platforms if unspecified)

getKeymap([defaults]) ⇒ Object

Returns a copy of the current key map. If the optional 'defaults' parameter is true, then a copy of the default key map is returned. In the default keymap each key is associated with an object containing commandID, key, and displayKey.

Kind: global function

ParamTypeDescription
[defaults]booleantrue if the caller wants a copy of the default key map. Otherwise, the current active key map is returned.

addBinding(command, keyBindings, platform, options) ⇒ Object

Add one or more key bindings to a particular Command. Returns record(s) for valid key binding(s).

Kind: global function

ParamTypeDescription
commandstring | CommandA command ID or command object
keyBindingsObjectA single key binding or an array of keybindings. In an array of keybinding platform property is also available. Example: "Shift-Cmd-F". Mac and Win key equivalents are automatically mapped to each other. Use displayKey property to display a different string (e.g. "CMD+" instead of "CMD=").
platformstringThe target OS of the keyBindings either "mac", "win" or "linux". If undefined, all platforms not explicitly defined will use the key binding. NOTE: If platform is not specified, Ctrl will be replaced by Cmd for "mac" platform
optionsobject
options.isMenuShortcutbooleanthis allows alt-key shortcuts to be registered.

getKeyBindings(command) ⇒ Array.<Object>

Retrieve key bindings currently associated with a command

Kind: global function
Returns: Array.<Object> - The object has two properties key and displayKey

ParamTypeDescription
commandstring | CommandA command ID or command object

getKeyBindingsDisplay(commandID) ⇒ string | null

Retrieves the platform-specific string representation of the key bindings for a specified command. This function is useful for displaying the keyboard shortcut associated with a given command ID to the user. If a key binding is found for the command, it returns the formatted key descriptor. Otherwise, it returns null.

Kind: global function
Returns: string | null - The formatted key binding as a string if available; otherwise, null.

ParamTypeDescription
commandIDstringThe unique identifier of the command for which the key binding is to be retrieved.

addGlobalKeydownHook(hook)

Adds a global keydown hook that gets first crack at keydown events before standard keybindings do. This is intended for use by modal or semi-modal UI elements like dialogs or the code hint list that should execute before normal command bindings are run.

The hook is passed two parameters, the first param is the original keyboard event. The second param is the deduced shortcut string like Ctrl-F if present for that event or null if not keyboard shortcut string. If the hook handles the event (or wants to block other global hooks from handling the event), it should return true. Note that this will only stop other global hooks and KeyBindingManager from handling the event; to prevent further event propagation, you will need to call stopPropagation(), stopImmediatePropagation(), and/or preventDefault() as usual.

Multiple keydown hooks can be registered, and are executed in order, most-recently-added first. A keydown hook will only be added once if the same hook is already added before.

(We have to have a special API for this because (1) handlers are normally called in least-recently-added order, and we want most-recently-added; (2) native DOM events don't have a way for us to find out if stopImmediatePropagation()/stopPropagation() has been called on the event, so we have to have some other way for one of the hooks to indicate that it wants to block the other hooks from running.)

Kind: global function

ParamTypeDescription
hookfunctionThe global hook to add.

removeGlobalKeydownHook(hook)

Removes a global keydown hook added by addGlobalKeydownHook. Does not need to be the most recently added hook.

Kind: global function

ParamTypeDescription
hookfunctionThe global hook to remove.

registerCustomKeymapPack(packID, packName, keyMap)

This can be used by extensions to register new kepmap packs that can be listed in the keyboard shortcuts panel under use preset dropdown. For EG. distribute a netbeans editor shortcuts pack via extension.

Kind: global function

ParamTypeDescription
packIDstringA unique ID for the pack. Use extensionID.name format to avoid collisions.
packNamestringA name for the pack.
keyMapObjecta keymap of the format {'Ctrl-Alt-L': 'file.liveFilePreview'} depending on the platform. The extension should decide the correct keymap based on the platform before calling this function.

getAllCustomKeymapPacks() ⇒ Array.<Object>

Responsible to get all the custom keymap packs

Kind: global function
Returns: Array.<Object> - an array of all the custom keymap packs, each pack is an object with keys: packID, packageName & keyMap

getCurrentCustomKeymapPack() ⇒ Object

To get the current custom keymap pack

Kind: global function
Returns: Object - the current custom keymap pack

resetUserShortcutsAsync() ⇒ Promise | Promise.<void> | *

resets all user defined shortcuts

Kind: global function

isInOverlayMode() ⇒ boolean

Whether the keyboard is in overlay mode or not

Kind: global function
Returns: boolean - True if in overlay mode else false

showShortcutSelectionDialog(command)

to display the shortcut selection dialog

Kind: global function

Param
command

canAssignBinding(commandId) ⇒ boolean

Returns true the given command id can be overriden by user.

Kind: global function

Param
commandId

UserKeyBinding : Object

Kind: global typedef