【问题标题】:Sending input to a windows application from outside从外部向 Windows 应用程序发送输入
【发布时间】:2017-01-31 10:16:27
【问题描述】:

在 Linux 中,我可以在 GNU screen 会话中启动一个程序,然后使用 screen 的 stuff 命令从外部向它发送输入,该命令发送的字符与我在程序中输入的完全一样。我是 Windows 开发新手,想知道 Windows 中是否存在类似功能?

【问题讨论】:

  • 你为什么用ConEmu标记你的问题?
  • 这就是我正在使用的终端,它似乎功能非常丰富。我希望 ConEmu 可能以某种方式支持这一点?
  • Windows 中的标准自动化基础结构是UI Automation。您可以使用Inspect 工具检查任何给定的应用程序是否公开了所需的接口。

标签: windows powershell gnu-screen conemu


【解决方案1】:

如果您不使用
AutoIT
AutoHotKey 等第 3 方应用程序,则有
vbscript sendkeys,而且相当复杂
Windows API SendMessage 方法。

这里最简单的似乎是Converting the Windows Script Host SendKeys Method(对powershell):

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[Microsoft.VisualBasic.Interaction]::AppActivate("Test.ps1 - Notepad")

[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("{F1}")

要评估 AppActivate 的窗口标题,您可以使用:

Get-Process|Where{$_.Mainwindowtitle}|select processName,Mainwindowtitle

【讨论】:

  • 谢谢,我现在有一些事情要尝试。
猜你喜欢
  • 2015-06-04
  • 1970-01-01
  • 2013-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多