Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
electron-localshortcut
Advanced tools
register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu
A module to register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu.
This is built to circumvent this Electron issue.
Note: Since this module internally use global-shortcut
native module, you should not use it until the ready
event of the app module is emitted. See electron docs.
npm install --save electron-localshortcut
const electronLocalshortcut = require('electron-localshortcut');
const BrowserWindow = require('electron').BrowserWindow;
const win = new BrowserWindow();
win.loadUrl('https://github.com');
win.show();
electronLocalshortcut.register(win, 'Ctrl+A', () => {
console.log('You pressed ctrl & A');
});
electronLocalshortcut.register(win, 'Ctrl+B', () => {
console.log('You pressed ctrl & B');
});
console.log(
electronLocalshortcut.isRegistered(win, 'Ctrl+A')
); // true
electronLocalshortcut.unregister(win, 'Ctrl+A');
electronLocalshortcut.unregisterAll(win);
If you omit the window argument of isRegistered
, unregisterAll
, unregister
and register
methods, the shortcut is registered as an app shortcut.
It is active when any window of the app is focused.
They differ from native global-shortcuts because they doesn't interfere with other apps running on the same machine.
If you register a shortcut for a window, this module unregister the shortcut when the window is hidden, unfocused or minimized, and automatically restore them when the window is restored and focused again.
If you register an app shortcut, this module unregister the shortcut when all windows of your app are hidden, unfocused or minimized, and automatically restore it when any window of your app is restored and focused again.
Disable all of the shortcuts registered on the BrowserWindow instance.
Registered shortcuts no more works on the window
instance, but the module keep a reference on them. You can reactivate them later by calling enableAll
method on the same window instance.
Parameters
win
BrowserWindow BrowserWindow instanceReturns Undefined
Enable all of the shortcuts registered on the BrowserWindow instance that you had previously disabled calling disableAll
method.
Parameters
win
BrowserWindow BrowserWindow instanceReturns Undefined
Unregisters all of the shortcuts registered on any focused BrowserWindow instance. This method does not unregister any shortcut you registered on a particular window instance.
Parameters
win
BrowserWindow BrowserWindow instanceReturns Undefined
Registers the shortcut accelerator
on the BrowserWindow instance.
Parameters
win
BrowserWindow BrowserWindow instance to register. This argument could be omitted, in this case the function register the shortcut on all app windows.accelerator
String the shortcut to registercallback
Function This function is called when the shortcut is pressed and the window is focused and not minimized.Returns Undefined
Unregisters the shortcut of accelerator
registered on the BrowserWindow instance.
Parameters
win
BrowserWindow BrowserWindow instance to unregister. This argument could be omitted, in this case the function unregister the shortcut on all app windows. If you registered the shortcut on a particular window instance, it will do nothing.accelerator
String the shortcut to unregisterReturns Undefined
Returns true
or false
depending on whether the shortcut accelerator
is
registered on window
.
Parameters
win
BrowserWindow BrowserWindow instance to check. This argument could be omitted, in this case the function returns whether the shortcut accelerator
is registered on all app windows. If you registered the shortcut on a particular window instance, it return false.accelerator
String the shortcut to checkReturns Boolean if the shortcut accelerator
is registered on window
.
The MIT License (MIT)
Copyright (c) 2017 Andrea Parodi
FAQs
register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu
The npm package electron-localshortcut receives a total of 29,628 weekly downloads. As such, electron-localshortcut popularity was classified as popular.
We found that electron-localshortcut demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.