Reputation: 59
I have made a application that comes in focus when I press the Global Shortcut keys when it is not in focus. I want the application to close with the press of same Global Shortcut key, if currently it is in focus.
Upvotes: 0
Views: 66
Reputation: 5322
You can use the win.isFocused()
flag like this:
globalShortcut.register('CommandOrControl+F', () => {
if (window.isFocused()) {
window.hide();
} else {
window.show();
}
});
So if the window is hidden then pressing the shortcut will show it and if the window is in focus then pressing the shortcut will hide it.
win.isFocused
Docs.
Upvotes: 1