Skip to content

Shortcuts Module

The Shortcuts module allows you to manage keyboard shortcuts for the desktop application. This enables your app to respond to specific key combinations (accelerators), improving user experience by providing quick access to common actions.

Overview

With the Shortcuts Module, you can:

  • Register hotkeys to trigger specific actions quickly.
  • Listen to keyboard shortcut press and release events.
  • Unregister shortcuts when they are no longer needed.
  • Check if a shortcut is currently registered.

Typical use cases include implementing keyboard shortcuts for opening dialogs, toggling features, or performing quick commands without navigating menus.

Methods

MethodParametersReturn TypeDescription
register()accelerator: string, callback: Function, options: ShortcutOptions (optional)Promise<void>Registers a keyboard shortcut with a callback.
unregister()accelerator: stringPromise<void>Unregisters the shortcut associated with the given accelerator.
unregisterAll()-Promise<void>Unregisters all registered shortcuts.
isRegistered()accelerator: stringbooleanChecks if a shortcut with the given accelerator is currently registered.

ShortcutOptions

FieldTypeDescription
emitEvent (optional)booleanWhether the shortcut should emit an event or not when triggered.

Shortcut Event Payload

When a shortcut event is triggered, the event payload contains the following fields:

FieldTypeDescription
acceleratorstringThe accelerator string representing the shortcut (e.g., Ctrl+Shift+X).
shortcutstringThe shortcut string triggered (may be the same as accelerator).
idstringThe unique identifier of the registered shortcut.
statestringThe state of the shortcut event, typically "pressed" or "released".
[key: string]anyAdditional properties depending on the event context.

Accelerators

Accelerators are strings that represent key combinations used to activate shortcuts. They specify one or more keys pressed together or in sequence to trigger an action within the application.

Examples of valid accelerators include:

  • Ctrl+Shift+X
  • Alt+Enter
  • Cmd+Option+S
  • Ctrl+K Ctrl+C

Note that accelerators reserved by the operating system should not be used, such as Ctrl+C, Cmd+Q, Alt+Tab, and similar combinations, to avoid conflicts and ensure consistent behavior.

KeyDescription
CtrlControl key (Windows/Linux)
AltAlternate key
ShiftShift key
CmdCommand key (macOS)
OptionOption key (macOS)

Example

js
// Register a global shortcut for Ctrl+Shift+X
Bubbledesk.globalShortcut.register(
    'Ctrl+Shift+X', // accelerator
    () => {console.log('Ctrl+Shift+X Shortcut triggered!')}, // callback
    {emitEvent: true} // options
);

// Listen for shortcut events
Bubbledesk.events.onShortcut((payload) => {
  if (payload.accelerator === 'Ctrl+Shift+X' && payload.state === 'pressed') {
    // Perform an action
  }
});

// Unregister the shortcut when no longer needed
Bubbledesk.globalShortcut.unregister('Ctrl+Shift+X').then(() => {
  console.log('Shortcut unregistered!');
});

Official OS Shortcut References

For detailed lists of system-reserved keyboard shortcuts, refer to the official OS documentation below.

Always verify which key combinations are reserved on each OS before registering global shortcuts in your application.

Notes

TIP

To avoid conflicts, always make sure that you haven't registered the same accelerator multiple times, and system predefined accelerators (like Ctrl+C) should not be used.

WARNING

Shortcut behavior may differ across operating systems. Some key combinations are reserved by the OS and cannot be overridden. Test your shortcuts on all target platforms to ensure consistent behavior.

All rights reserved.