O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Registering global keyboard shortcuts

Menu in tray is a solution, but actually, we have an option to perform capturing actions even without opening the menu. NW.js allows us to assign global keyboard shortcuts:

  const shortcut = new nw.Shortcut({       key: "Shift+Alt+4",       active: () => {}       failed: console.error     });     nw.App.registerGlobalHotKey( shortcut ); appWindow.on( "close", () => nw.App.unregisterGlobalHotKey( shortcut ) ); window.addEventListener( "beforeunload", () => nw.App.unregisterGlobalHotKey( shortcut ), false ); 

We use nw.Shortcut to create an object representing a shortcut. With nw.App.registerGlobalHotKey, the shortcut is registered. We use nw.App.unregisterGlobalHotKey to unregister the shortcut when the application closes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required