vbs SendKeys 仅发送到特定窗口 [英] vbs SendKeys only to specific window

查看:44
本文介绍了vbs SendKeys 仅发送到特定窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 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 激活它?在 WinAPI 中,除了活动窗口之外,您无法可靠地将击键发送到任何窗口.

如果您无论如何都打算尝试(当出现问题时不要抱怨if),根据链接的问题,您需要使用 SendMessage 向窗口发送一系列消息.

If you intend to try anyway (don't complain if 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 仅发送到特定窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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