将密钥代码发送到 Windows 中正在运行的应用程序 [英] Send a key-code to a running application in windows

查看:49
本文介绍了将密钥代码发送到 Windows 中正在运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Windows 10.是否可以(从命令行)向已运行的 Windows 应用程序发送键码?(这样这个应用程序会认为我按下了某个键?)

I am running windows 10. Is there a possibility to send (from the command line) a keycode to a windows application that is already running? (such that this application will think that I pressed a certain key?)

请求是从命令行或其他发送密钥,以控制应用程序选项卡菜单命令.例如打开或关闭文件或关闭应用程序本身.

The request is to send keys from the command line or other, to control application tab menu command. For example to open or close file or close the application itself.

推荐答案

(echo with createobject^("wscript.shell"^)
echo .run "notepad.exe"
echo wscript.sleep 1000
echo .sendkeys "IN-THE-NAME-OF-ALLAH"
echo wscript.sleep 300
echo .sendkeys "(%%F)S"
echo  wscript.sleep 2000
echo  .sendkeys "myText.txt"
echo .sendkeys "{enter}" 
echo wscript.sleep 1000
echo .sendkeys "%%{F4}"
echo end with) > %temp%\sk.vbs
start /w %temp%\sk.vbs

这个例子展示了如何将密钥从 cmd 发送到 Notepad.exe 等应用程序来控制.

This example show how can send key from cmd to application like Notepad.exe to control .

在你的情况下不需要这行 2 echo .run "notepad.exe" 因为你已经运行了你的应用程序,如果你想通过这个批处理文件运行你的应用程序,你将删除 notepad.exe并为您的应用程序添加完整路径.

in your situation no need for this line 2 echo .run "notepad.exe" because you already run your application if you like to run your application through this batch file you will remove notepad.exe and add Full path for your application instead .

然后根据需要增加第 3 行的睡眠时间记住 1000 平均 1 秒

and then increase in line 3 sleep time as you like remember 1000 mean 1 sec

在第 6 行 (%%F)S 表示发送键 Alt+F 打开文件选项卡菜单,然后发送键 S 从此菜单中选择保存

in line 6 (%%F)S mean send key Alt+F to open File tab menu then Send key S to choose Save from this menu

在第 11 行 %%{F4} 表示发送键 Alt+F4 关闭应用程序

in line 11 %%{F4} mean send key Alt+F4 to close the application

这篇关于将密钥代码发送到 Windows 中正在运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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