Electron 注册全局快捷键(globalShortcut) ¶
var app = require('app') var globalShortcut = require('electron').globalShortcut app.on('ready', function() { // Register a 'ctrl+x' shortcut listener. var ret = globalShortcut.register('ctrl+x', function() { console.log('ctrl+x is pressed') }) if (!ret) { console.log('registration failed') } // Check whether a shortcut is registered. console.log(globalShortcut.isRegistered('ctrl+x')) }) app.on('will-quit', function() { // Unregister a shortcut. globalShortcut.unregister('ctrl+x') // Unregister all shortcuts. globalShortcut.unregisterAll() })
复制成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
clipboard 剪切板事件 clipboard 模块以及 nativeImage 模块 ¶
const { clipboard, nativeImage } = require('electron') clipboard.writeText('这是一个机器码') console.log(clipboard.readText()) let img = nativeImage.createFromPath('static/favicon2.ico') clipboard.writeImage(img) const imgDataURL = clipboard.readImage().toDataURL() const img3 = new Image() img3.src = imgDataURL document.body.appendChild(img3)
复制成功
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9