如何在节点Webkit上执行组合键,例如C#sendkeys [英] How execute a combination key on node-webkit like c# sendkeys

查看:66
本文介绍了如何在节点Webkit上执行组合键,例如C#sendkeys的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个Webkit应用程序,该应用程序在txt上注册了一些小代码,例如代码片段,以便以后在其他应用程序上使用.我可以找到我的代码段"并在剪贴板上设置内容.

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.

但是,我也想像C#上的SendKeys函数那样在Node-Webkit上运行"Ctrl + v"组合键.

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

现在,我需要手动按组合键"Ctrl + v"以粘贴到另一个应用程序中.

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

我也正在考虑如何运行另一个文件,例如一个小的exe程序,该文件会执行SendKey函数并关闭它.但是我更喜欢一个node-webkit函数,而无需调用其他脚本或exe程序.

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.

推荐答案

好吧,我正在互联网上寻找没有结果的答案.

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

但是我实现的最佳解决方案是使用VBScript帮助文件.

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

而且效果很好!!

该应用程序调用粘贴功能来执行"paste.vbs"文件.

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

paste.vbs

paste.vbs

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


myapp.js


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.

如果要与其他操作系统兼容,则必须使用类似于VBS的另一个命令文件

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 .

我可以在GitHub上创建一个项目来加载代码,以便其他人可以使用它或帮助我改进代码.

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

这篇关于如何在节点Webkit上执行组合键,例如C#sendkeys的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆