Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
electron-webcontents-shortcut
Advanced tools
Readme
This project is inspired by another project, electron-localshortcut, with a similar implementation principle but enhanced functionality. In comparison to electron-localshortcut
, this project offers greater flexibility, allowing users to freely bind shortcuts in the multi-process environment of Electron applications, including BrowserWindow
, BrowserView
, and Webview
.
In electron-localshortcut
, shortcuts can only be bound to a BrowserWindow
, limiting its use in Electron applications with multiple processes that may involve the use of BrowserView
or Webview
. To address this limitation, this project relaxes the constraints imposed by electron-localshortcut
, enabling users to bind shortcuts to any source of WebContents
, thus better accommodating the needs of multi-process applications.
WebContents
, including BrowserWindow
, BrowserView
, Webview
, and more.Install via npm:
npm install electron-webcontents-shortcut
Import this module into your Electron project:
const shortcutManager = require('electron-webcontents-shortcut');
Then, use the following methods to bind shortcuts:
const { register } = shortcutManager;
app.whenReady().then(() => {
const win = new BrowserWindow({
width: 600,
height: 400,
});
win.loadURL('https://www.electronjs.org//');
register(win.webContents, 'Ctrl+Shift+O', () => {
console.log('Ctrl+Shift+O');
win.webContents.openDevTools({ mode: 'detach' });
});
});
isAccelerator(input: string): boolean
Checks whether a given string is a valid representation of a keyboard accelerator. A valid accelerator should consist of any number of modifier keys followed by a regular key. For example, Shift+Alt+P
.
unregisterAll(webContents: WebContents): void
Unregisters all keyboard shortcuts associated with the specified webContents
.
register(webContents: WebContents, accelerator: string | string[], callback: () => void): void
Registers a keyboard shortcut on the specified webContents
. The accelerator
parameter can be a string or an array of strings representing the keyboard shortcut(s), and the callback
function will be invoked when the shortcut is triggered.
unregister(webContents: WebContents, accelerator: string | string[]): void
Unregisters the specified keyboard shortcut(s) associated with the given webContents
.
isRegistered(webContents: WebContents, accelerator: string): boolean
Checks whether a specific keyboard shortcut is registered on the specified webContents
.
const {
isAccelerator,
register,
unregister,
unregisterAll,
isRegistered,
} = require('electron-webcontents-shortcut');
// Check if a string is a valid accelerator
if (isAccelerator('Ctrl+A')) {
const webContents = // ... obtain WebContents instance
// Register a keyboard shortcut
register(webContents, 'Ctrl+A', () => {
// Handle the shortcut
});
// Check if a shortcut is registered
if (isRegistered(webContents, 'Ctrl+A')) {
// Do something
}
// Unregister a shortcut
unregister(webContents, 'Ctrl+A');
// Unregister all shortcuts
unregisterAll(webContents);
}
If you encounter any issues or have suggestions for improvement, feel free to raise an issue or submit a pull request. We welcome and appreciate your contributions!
This project is licensed under the MIT License. For details, see the LICENSE file.
FAQs
register/unregister a keyboard shortcut locally to a webContents instance, using `before-input-event`
The npm package electron-webcontents-shortcut receives a total of 0 weekly downloads. As such, electron-webcontents-shortcut popularity was classified as not popular.
We found that electron-webcontents-shortcut demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.