如何使用 VB 脚本将后台窗口模拟为活动状态



如何使用VB脚本将后台窗口模拟为活动状态?

我需要将一些键盘代码命令发送到某个后台窗口(我知道相关的VB函数),但它仅在窗口处于活动状态时才有效。如果窗口确实处于活动状态,则我无法在前台执行任何操作。

那么无论如何都要

将窗口模拟为活动状态吗?

是的,看这个例子

Dim oShell
Set oShell = CreateObject("WScript.Shell")
'bring the window to front
'title must be exactly what you see in the titlebar of the window
oShell.AppActivate "title of your window" 
WScript.Sleep 500 'give the window the time to activate, time is in miliseconds
oShell.SendKeys "{ENTER}" 'you can send keystrokes to this window
Set oShell = nothing

如果您想最小化该窗口,您可以发送击键来执行此操作,但这取决于语言,因此请先手动尝试它们。下面从 miNimize 发送击键 Alt (%) 空格和 N。尝试在窗口中按 Alt-空格键以获取控制此键的菜单

oShell.SendKeys "(% )N" 

最新更新