Angel Fraga Parodi Angel Fraga Parodi - 1 year ago 248
Node.js Question

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

I made a Webkit app that register small codes on txt like snippets to use later on other apps. I can find my "snippet" and set the content on clipboard.

But also , I would like run "Ctrl+v" keys combination on Node-Webkit like the SendKeys function on C#.

Now I need press manually keys combination "Ctrl+v" to paste in another app.

Also i was thinking how run another file like a small exe program that do it the SendKey function and close it. But I prefer a node-webkit function without call other script or exe program.

It ´s posible to do it , and How can i do it ? Thanks guys.

Answer Source

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.


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


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');

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download