electron-capture-screen
electron截图插件
安装
yarn add electron-capture-screen
如果使用了webpack打包主进程,需要在webpack配置中添加:
module.exports = {
// ....
externals: {
'electron-capture-screen': 'require("electron-capture-screen")'
}
}
使用
import {app, globalShortcut} from 'electron';
import CaptureScreen from 'electron-capture-screen';
app.on('ready', () => {
const captureScreen = new CaptureScreen();
globalShortcut.register('ctrl+alt+a', () => {
captureScreen.init();
});
globalShortcut.register('Esc', () => {
captureScreen.hide();
});
captureScreen.on('capture', dataURL => {
console.log(dataURL);
});
});