import {
KeyboardShortcut,
Viewer,
} from '@stereograph/teiaviewer';
/**
* Use declaration merging to declare the new shortcut action
*/
declare module '@stereograph/teiaviewer' {
interface KeyboardShortcutRegistry {
'objects.custom_action': true;
}
}
class CustomActionShortcut extends KeyboardShortcut {
readonly action = 'objects.custom_action';
readonly label = 'Custom action';
constructor() {
// Default binding is ctrl+X
super({
ctrl: true,
key: 'X',
});
}
override async execute(_viewer: Viewer, _isHolding: boolean): Promise<void> {
// Perform any custom action
}
}
const viewer = new Viewer();
// Adds the new shortcut
viewer.viewport!.shortcutController.addShortcut(new CustomActionShortcut());
// Modify its binding
viewer.viewport!.shortcutController.setBinding('objects.custom_action', {
ctrl: true,
shift: true,
key: 'KeyZ',
useKeycode: true,
});