Web/JavaScript

[Electron] Global Shortcut

llHoYall 2020. 9. 1. 21:51

2020/08/31 - [Web/JavaScript] - [Electron] Getting Started

2020/08/31 - [Web/JavaScript] - [Electron] BrowserWindow

2020/09/01 - [Web/JavaScript] - [Electron] IPC (Inter Process Communication)

2020/09/01 - [Web/JavaScript] - [Electron] Menu

2020/09/01 - [Web/JavaScript] - [Electron] Global Shortcut

2020/09/01 - [Web/JavaScript] - [Electron] Tray


This post is about the global shortcut of Electron.

 

The global shortcut is handled by the main process.

Open the main.js file.

const globalShortcut = electron.globalShortcut;

app.on("ready", () => {
  createWindow();
  globalShortcut.register("alt+1", () => {
    console.log("Global shortcut works well");
  });
});

app.on("will-quit", () => {
  globalShortcut.unregisterAll();
});

Define a globalShortcut and register it.

I made a <ALT+1> and it will show a log.

And unregister it when application quitting.

 

Now, let's run.

If you input the shortcut keys, the log message will show in the terminal.

This is a simple way to make global shortcuts in Electron.

반응형