How execute a combination key on node-webkit like c# sendkeys

ぐ巨炮叔叔 提交于 2019-12-01 14:45:47

Well, I was looking for an answer on the Internet without results.

But the best solution i 've implemented is to use a VBScript help file .

And it works well !!

The app calls the Paste function to execute the " paste.vbs " file.


paste.vbs

set shell = CreateObject("WScript.Shell") 
WScript.Sleep 300
shell.SendKeys "^V"

myapp.js

var gui = require('nw.gui');
var win = gui.Window.get();

function getCommandLine() {
   switch (process.platform) { 
      case 'darwin' : return 'open';
      case 'win32' : return 'start';
      case 'win64' : return 'start';
      default : return 'xdg-open';
   }
} 
function Paste(){
    var sys = require('util');
    var exec = require('child_process').exec; 
    exec(getCommandLine() + ' ' + "paste.vbs"); 
} 
function useSnippet(content){
    var clipboard = gui.Clipboard.get(); 
    clipboard.set(content, 'text');
    win.minimize();
    Paste();
} 

Now you can get the file contents for pasting into other applications.

If you want compatibility with other operating systems, you must use another command file similar to VBS

I use a list of files and reading passages content of a search list .

I can create a project on GitHub to load the code so that other people can use it or help me improve the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!