简体   繁体   English

从 Electron 中的系统剪贴板复制/粘贴

[英]Copy/paste from system clipboard in Electron

I'm building a simple electron app to show some text on the screen on top of everything else.我正在构建一个简单的 electron 应用程序,以在屏幕上显示一些文本。 There is a keyboard shortcut that opens a pop-up with text.有一个键盘快捷键可以打开一个带有文本的弹出窗口。 I want to add one little function.我想加一点function。 The best case scenario would be: I select some text wherever on my computer and press a dedicated keyboard shortcut and this text shows up in the pop-up.最好的情况是:我 select 在我的计算机上的任何地方都有一些文本,然后按专用的键盘快捷键,这个文本会显示在弹出窗口中。 It copies the text and pastes it in the app.它复制文本并将其粘贴到应用程序中。 I guess it will be problematic for safety reasons (coping from system clipboard) but maybe there is a way around it?我想出于安全原因(从系统剪贴板应对)会有问题,但也许有办法解决它? Is it possible to do it?有可能做到吗? Is there a walk-around that will be similar to the one I described?是否有与我描述的类似的走动?

In other words, now I need 3 steps: ctrl+C (to copy selected text) ctrl+M (to open the app) ctrl+V (to paste it in the app).换句话说,现在我需要 3 个步骤:ctrl+C(复制选定的文本)ctrl+M(打开应用程序)ctrl+V(将其粘贴到应用程序中)。 Can I reduce it to only one step with only my dedicated keyboard shortcut or to two steps: Ctrl+C + Ctrl+M?我可以仅使用我的专用键盘快捷键将其减少到一个步骤,还是减少到两个步骤:Ctrl+C + Ctrl+M?

Thanks!谢谢!

you can create an app where the window is not showing ( use parameter show of browser-window ),您可以创建一个 window 未显示的应用程序( 使用浏览器窗口的参数 show ),
maybe create a trayicon to visualise that the app is running.也许创建一个托盘图标来可视化应用程序正在运行。

Than define in your app a global shortcut (Ctrl+M) global-shortcuts in electron .比在您的应用程序中定义全局快捷方式 (Ctrl+M) 全局快捷方式 electron

In your shortcut callback set window to visible and get the clipboard content.在您的快捷回调中,将 window 设置为可见并获取剪贴板内容。
Electron has an api for that, you can find it here Electron 有一个 api , 你可以在这里找到它

than just add the text to the window不仅仅是将文本添加到 window

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM