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 or reloads.
That brings us to the following service:
./js/Service/Shortcut.js
const appWindow = nw.Window.get(); import { toggleRecording } from "../Actions"; import { SCREENSHOT_DEFAULT_FILENAME, ANIMATION_DEFAULT_FILENAME...