问题描述
我有这个 VBScript
I have this VBScript
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "KEYS TO SEND"
此代码将向 Ative Top 窗口发送 Keys Strokes
This code will send Keys Strokes to Ative Top window
如何只将击键发送到特定窗口?
How can I send the keystrokes only to specific window?
推荐答案
WSH 中的预期方式是首先使用 WshShell.AppActivate
正如其他人指出的那样.
The intended way in WSH is to first activate the window with WshShell.AppActivate
as others noted.
根据 如何将击键发送到窗口而不必使用 Windows API 激活它? ,),根据链接的问题,您需要使用 SendMessage 向窗口发送一系列消息代码>.
If you intend to try anyway (don't complain when things go wrong), as per the linked question, you need to send a series of messages to the window with SendMessage
.
WSH 中没有调用 WinAPI 的内置方法.因此,要么使用其标准库提供对 WinAPI 和/或包装器的访问的另一种语言,要么使用像 DynamicWrapperX.
There's no built-in way in WSH to call WinAPI. So, either use another language whose standard library provides access to WinAPI and/or wrappers over them, or a 3rd-party COM object like DynamicWrapperX.
作为旁注,您可能希望考虑使用专用的 UI 自动化语言,例如 AutoIt 或 Autohotkey.如果由于某种原因仍然需要使用WSH,可以通过COM接口调用前者.
As a side note, you may wish to consider a dedicated UI automation language like AutoIt or Autohotkey. The former can be called via a COM interface if you still need to use WSH for some reason.
这篇关于vbs SendKeys 仅发送到特定窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!