concept global shortcut in category electron

This is an excerpt from Manning's book Electron in Action.
Unlike traditional web applications, Electron applications aren’t limited to the browser. You can create applications that live in the menu bar or the system tray. See figure 1.6. You can even register global shortcuts to trigger these applications or any of their abilities with a special keystroke from anywhere in the operating system.
If you look closely, you’ll notice that each of these items has a keyboard shortcut as well. In addition to these menu-based accelerators, we register global shortcuts with the operating system that allow the user to activate this menu or create a new clipping from anywhere.
All the accelerators we’ve used so far have worked only when the application is actively being used. By using the globalShortcut module, Electron also allows us to register global shortcuts with the operating system that can be activated even when the application is in the background. We’ll register two global shortcuts for Clipmaster: one to trigger the menu to appear, and another to save the contents of the clipboard to Clipmaster without needing to trigger the menu at all.
Listing 9.12. Registering a global shortcut: ./app/main.js
const path = require('path'); const { app, clipboard, globalShortcut, #1 Menu, Tray, systemPreferences } = require('electron'); const clippings = []; let tray = null; app.on('ready', () => { if (app.dock) app.dock.hide(); tray = new Tray(path.join(__dirname, '/Icon.png')); if (process.platform === 'win32') { tray.on('click', tray.popUpContextMenu); } const activationShortcut = globalShortcut.register( 'CommandOrControl+Option+C', () => { tray.popUpContextMenu(); } #2 ); if (!activationShortcut) { #3 console.error('Global activation shortcut failed to register'); } const newClippingShortcut = globalShortcut.register( 'CommandOrControl+Shift+Option+C', () => { addClipping(); } #4 ); if (!newClippingShortcut) { #5 console.error('Global new clipping shortcut failed to register'); } updateMenu(); tray.setToolTip('Clipmaster'); }); const updateMenu = () => { // ... }; const addClipping = () => { // ... }; const createClippingMenuItem = (clipping, index) => { // ... };