BetaBetabindBind a command to a specific key combination to add it to the registry
When a user presses the specified key combination, the command will be dispatched through the CommandBus. The command must already have a handler registered on the command bus before binding.
If the same key combination is bound to multiple commands, all commands will be executed in the order they were registered.
the string representation of keys (e.g., 'ctrl+s', 'alt+shift+n', 'g i')
the command instance to trigger when keys are pressed
BetagetGet a list of the key bindings that are currently in the registry
Returns all active keybindings across all components. Useful for debugging, displaying keyboard shortcuts to users, or detecting conflicts.
the list of all active keybindings with their commands
BetaisChecks if a key combination or a specific keybinding is already bound
Use this method to detect conflicts before binding new keybindings. When called with just a key combination, returns true if any command is bound to those keys. When called with both keys and a command, returns true only if that specific combination exists.
the string representation of a key combination (e.g., 'ctrl+s')
Optionalcommand: objectoptional command instance to check for a specific binding
true if the key combination is bound (to any or the specified command), false otherwise
BetaunbindUnbind a keybinding to remove it from the registry
Removes the association between a key combination and a command. After unbinding, pressing the key combination will no longer trigger the command. This is essential for cleanup when components are removed from the DOM.
If multiple commands are bound to the same key combination, only the specified command will be unbound.
the string representation of the key combination (e.g., 'ctrl+s')
the command instance connected to the key combination
Service for binding keyboard shortcuts to execute commands
A keybinding is a sequence or key combination on a computer keyboard which invokes commands. This service supports key bindings as a way of responding to individual keys typed by a user. The key combination can be pressing a single key or a sequence of keys one after the other.
The service works together with the CommandBus to execute the commands and a command needs to already be registered on the command bus in order to be bound as a keyboard shortcut.
Keybindings are scoped to the component that creates them and should be cleaned up when the component is removed from the DOM to prevent memory leaks and unintended behavior.
Key Combination Format
Key combinations can be:
'a','enter','escape''ctrl+s','alt+shift+n','meta+k''g i'(press 'g' then 'i')Supported modifiers:
ctrl,alt,shift,meta(Command on Mac)Example: Binding a command to a key combination
Example: Checking for conflicts before binding
Example: Vim-style key sequences
Example: Usage in a component
Note
This service is work in progress