Contents

GlobalShortcut

The global keyboard shortcut manager.

You can use this class to register and unregister global keyboard shortcuts, check if a shortcut is registered, and define the callback function to be called when the shortcut is triggered.

The global keyboard shortcuts are registered for the entire system, so they can be used even when the application does not have the keyboard focus.

When the application is terminated, all the registered global keyboard shortcuts are unregistered automatically.

You can use this class to override the standard global keyboard shortcuts that are already registered by the operating system or other applications.

import { globalShortcut } from '@mobrowser/api';

Example 

import { globalShortcut } from '@mobrowser/api';

// Register a global keyboard shortcut
const success = globalShortcut.register('CommandOrControl+Shift+F', () => {
  console.log('CommandOrControl+Shift+F has been pressed')
})

// Unregister the global shortcut if it is no longer needed
globalShortcut.unregister('CommandOrControl+Shift+F')

Methods 

register() 

register(shortcut: Shortcut, callback: () => void): boolean;

Registers a global keyboard shortcut if it is not already registered.

This method can be used to override the global keyboard shortcuts that are already registered by the operating system or other applications. For example, you can override the standard macOS shortcuts such as CMD+C or CMD+V.

ParameterTypeDescription
shortcutShortcutThe shortcut to register.
callback() => voidThe callback function to be called when the shortcut is triggered.

Return value 

Returns true if the shortcut was registered successfully. Returns false if the shortcut was already registered by this method or the given shortcut cannot be registered due to the operating system restrictions.

Example 

import { globalShortcut } from '@mobrowser/api';

// Register a global keyboard shortcut
const success = globalShortcut.register('CommandOrControl+Shift+D', () => {
  console.log('CommandOrControl+Shift+D has been pressed')
})

isRegistered() 

isRegistered(shortcut: Shortcut): boolean;

Checks if a global keyboard shortcut is registered using the register() method.

This method cannot be used to check if the given global keyboard shortcut is registered by the operating system or other applications.

ParameterTypeDescription
shortcutShortcutThe shortcut to check if it is registered.

Return value 

Returns true if the shortcut is registered, false otherwise.

unregister() 

unregister(shortcut: Shortcut): void;

Unregisters the given global keyboard shortcut.

If the shortcut was not registered, this method does nothing.

ParameterTypeDescription
shortcutShortcutThe shortcut to unregister.

Example 

import { globalShortcut } from '@mobrowser/api';

// Unregister a global keyboard shortcut
globalShortcut.unregister('CommandOrControl+Shift+D')

unregisterAll() 

unregisterAll(): void;

Unregisters all the previously registered global keyboard shortcuts.