Electron 可以使用 remote 模块来获取鼠标选中的内容。

示例代码:

const { remote } = require('electron');

document.addEventListener('mouseup', () => {
  const selection = remote.getCurrentWindow().webContents.getSelection().toString();
  console.log(selection);
});

代码说明:

  1. 首先需要引入 remote 模块。
  2. 监听 mouseup 事件,当鼠标松开时执行回调函数。
  3. 使用 remote.getCurrentWindow().webContents.getSelection().toString() 获取当前窗口的选中内容,并转换成字符串。
  4. 打印选中内容。

需要注意的是,该方法只能在渲染进程中使用。

electron 获取鼠标选中的内容

原文地址: https://www.cveoy.top/t/topic/f4Jv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录