electron 获取鼠标选中的内容
Electron 可以使用 remote 模块来获取鼠标选中的内容。
示例代码:
const { remote } = require('electron');
document.addEventListener('mouseup', () => {
const selection = remote.getCurrentWindow().webContents.getSelection().toString();
console.log(selection);
});
代码说明:
- 首先需要引入
remote模块。 - 监听
mouseup事件,当鼠标松开时执行回调函数。 - 使用
remote.getCurrentWindow().webContents.getSelection().toString()获取当前窗口的选中内容,并转换成字符串。 - 打印选中内容。
需要注意的是,该方法只能在渲染进程中使用。
原文地址: https://www.cveoy.top/t/topic/f4Jv 著作权归作者所有。请勿转载和采集!