electron-localshortcut
A module to register/unregister a keyboard shortcut
locally to a BrowserWindow instance, without using a Menu.
Installation
npm install --save electron-localshortcut
Usage
const electronLocalshortcut = require('electron-localshortcut');
const BrowserWindow = require('browser-window');
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')
);
electronLocalshortcut.unregister(win, 'Ctrl+A');
electronLocalshortcut.unregisterAll(win);
Methods
The electron-localshortcut
module has following methods:
register(window, accelerator, callback)
window
BrowserWindow instanceaccelerator
Acceleratorcallback
Function
Registers a shortcut of accelerator
on the window
BrowserWindow instance. The callback
is called when the registered shortcut is pressed by the user, only if window
is focused.
isRegistered(window, accelerator)
Returns true
or false
depending on whether the shortcut accelerator
is
registered on window
.
unregister(window, accelerator)
Unregisters the shortcut of accelerator
registered on the BrowserWindow instance.
unregisterAll(window)
window
BrowserWindow instance
Unregisters all of the shortcuts registered on the BrowserWindow instance.
License
The MIT License (MIT)
Copyright (c) 2015 Andrea Parodi