hotkey - Hotkey API
@types IPublicApiHotkey
> @since v1.0.0
Module Overview
Hotkey binding API for custom project shortcuts.
Methods
bind
Bind a hotkey
/**
* Bind a hotkey
* bind hotkey/hotkeys,
* @param combos Hotkey combos, e.g. ['command + s'], ['ctrl + shift + s']
* @param callback Callback function
* @param action
* @returns
*/
bind(
combos: string[] | string,
callback: IPublicTypeHotkeyCallback,
action?: string,
): IPublicTypeDisposable;
Related types
Usage Examples
Basic example
hotkey.bind('command+s', (e) => {
e.preventDefault();
// Logic to run when command+s is pressed
});
Bind multiple hotkeys at once
hotkey.bind(['command+s', 'command+c'], (e) => {
e.preventDefault();
// Logic to run when command+s or command+c is pressed
});
Save hotkey configuration
import { hotkey } from '@rchh/lowcode-engine';
function saveSchema(schema) {
// Schema save logic
}
const saveSampleHotKey = (ctx: IPublicModelPluginContext) => {
return {
name: 'saveSample',
async init() {
hotkey.bind('command+s', (e) => {
e.preventDefault();
saveSchema();
});
},
};
};
saveSampleHotKey.pluginName = 'saveSampleHotKey';
plugins.register(saveSampleHotKey);