gpt4 book ai didi

vbscript - 如何使用 Window Script Host 查找事件(前台)窗口的窗口标题

转载 作者:行者123 更新时间:2023-12-02 20:27:16 26 4
gpt4 key购买 nike

我想使用 Window Script Host(WSH) 查找当前事件(具有焦点)的窗口的标题,因为我希望我的 WSH 脚本仅在所需窗口处于事件状态时才发送键。

注意*我无法使用替代方案,即在调用 sendkeys 之前激活所需的窗口。

感谢任何帮助。

最佳答案

简短回答:你不能。至少在没有为相关 Windows API 调用编写 COM 包装器的情况下是这样。

你不能只使用AppActivate并检查结果吗?

Set oShell = CreateObject("WScript.Shell")
If oShell.AppActivate "Untitled - Notepad" Then
oShell.SendKeys "Hello, world!"
End If


长答案:要获取事件窗口标题,您需要调用 Windows API GetWindowText函数并传递 GetForegroundWindow()处理。 VBScript 和 Windows Script Host 不支持 Windows API 调用,因此您需要围绕这些函数编写一个 COM 包装器,然后可以在脚本中使用它。以下是示例:

Get current active Window title in C

How do I get the title of the current active window using c#?

关于vbscript - 如何使用 Window Script Host 查找事件(前台)窗口的窗口标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26341753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com