在电子应用中模拟CTRL V



我正在使用电子应用程序,并且有一个GlobalShortCut.Register事件。我想要的是,当用户按此快捷方式时,请隐藏我的应用程序窗口,并在后台应用中模拟糊状( ctrl v ),就像文本编辑器一样。这可以用电子?

如果您想使用剪贴板,以复制电子应用程序,请使用以下代码。这使用了剪贴板方法:

const clipboard = require('electron').clipboard
const copyBtn = document.getElementById('copy-to')
const copyInput = document.getElementById('copy-to-input')
copyBtn.addEventListener('click', function () {
  if (copyInput.value !== '') copyInput.value = ''
  copyInput.placeholder = 'Copied! Paste here to see.'
  clipboard.writeText('Electron Demo!')
})

如果您想做 当点击某个键组合时(例如CTRL V),您可以使用加速器或使用GlobalShortCut创建自己的组合。

const {app, globalShortcut} = require('electron')
app.on('ready', () => {
  // Register a 'CommandOrControl+Y' shortcut listener.
  globalShortcut.register('CommandOrControl+Y', () => {
    // Do stuff when Y and either Command/Control is pressed.
  })
})

最新更新