electron-localshortcut

Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu

Github星跟蹤圖

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.

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

	console.log(
		electronLocalshortcut.isRegistered(win, 'Ctrl+A')
	);      // true

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

App shortcuts.

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.

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 it 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

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. This method does not unregister any shortcut you registered on
a particular window instance.

Parameters

  • win BrowserWindow BrowserWindow instance

Returns Undefined

register

Registers the shortcut acceleratoron 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 , Array<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.
    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 , Array<String>) the shortcut to unregister

Returns Undefined

isRegistered

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 check

Returns Boolean if the shortcut accelerator is registered on window.

License

The MIT License (MIT)

Copyright (c) 2017 Andrea Parodi

主要指標

概覽
名稱與所有者parro-it/electron-localshortcut
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2015-11-02 17:41:35
推送於2024-03-23 03:53:59
最后一次提交2019-12-07 18:24:34
發布數26
最新版本名稱v3.2.1 (發布於 2019-11-12 07:57:12)
第一版名稱v0.0.1 (發布於 2015-11-02 18:42:29)
用户参与
星數423
關注者數11
派生數38
提交數196
已啟用問題?
問題數45
打開的問題數9
拉請求數19
打開的拉請求數3
關閉的拉請求數42
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?