windows - Send a key-code to a running application in 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 等应用程序以控制 .
在您的情况下不需要此第 2 行echo .run "notepad.exe"
,因为您已经运行了您的应用程序,如果您想通过此批处理文件运行您的应用程序,您将删除 notepad.exe 并为您的应用程序添加完整路径。
然后根据需要增加第 3 行的睡眠时间记住 1000 平均 1 秒
在第 6 行中,(%%F)S
表示发送键 Alt+F 以打开文件选项卡菜单,然后发送键 S 以从此菜单中选择保存
在第 11 行中,%%{F4}
表示发送键 Alt+F4 以关闭应用程序
推荐阅读
- plot - 无法在 Octave 中绘制阶跃响应
- java - 插入数据时出现无效的数据库路径错误
- javascript - 如何让我的营业时间出现在周末?
- python - 将日志级别设置为处理程序在 python 中不起作用
- amazon-web-services - 无法在 AWS ubuntu 上安装任何东西
- python-3.x - 文本分类器训练数据未通过 spacy debug-data CLI 正确加载
- laravel - 如何使用 Laravel 模型保存和检索 base64 编码数据
- azure - 如何将部门添加到 Azure AD 令牌
- php - Symfony 3.4 为什么 Formtype 的 CollectionType 不发布值
- c - 当流不为 0 时 fgetc() 返回 EOF