🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@beaker/electron-localshortcut

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beaker/electron-localshortcut

register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
3
Created
Source

electron-localshortcut

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.

Forked from parro-it/electron-localshortcut to add support for windows' child webviews.

Travis Build Status NPM module NPM downloads Greenkeeper badge

Installation

npm install --save electron-localshortcut

Usage

	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');
	});

	electronLocalshortcut.register(win, ['Ctrl+R', 'F5'], () => {
        console.log('You pressed ctrl & R or F5');
    });

	electronLocalshortcut.unregister(win, 'Ctrl+A');
	electronLocalshortcut.unregisterAll(win);

App shortcuts.

They differ from native global-shortcuts because they doesn't interfere with other apps running on the same machine.

Shortcut behaviour.

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.

API

register

Registers the shortcut acceleratoron the BrowserWindow instance.

Parameters

  • win BrowserWindow BrowserWindow instance to register.
  • accelerator String the shortcut to register
  • callback Function This function is called when the shortcut is pressed and the window is focused and not minimized.

Returns Undefined

unregister

Unregisters the shortcut of accelerator registered on the BrowserWindow instance.

Parameters

  • win BrowserWindow BrowserWindow instance to unregister.
  • accelerator String the shortcut to unregister

Returns Undefined

disableAll

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 instance

Returns Undefined

enableAll

Enable all of the shortcuts registered on the BrowserWindow instance that you had previously disabled calling disableAll method.

Parameters

  • win BrowserWindow BrowserWindow instance

Returns Undefined

unregisterAll

Unregisters all of the shortcuts registered on any focused BrowserWindow instance.

Parameters

  • win BrowserWindow BrowserWindow instance

Returns Undefined

License

The MIT License (MIT)

Copyright (c) 2017 Andrea Parodi

Keywords

electron

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

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.

Install

Related posts