Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

vbscript - How to mock the background window to active state using VB script?

How to mock the background window to active state using VB script?

There is some keycode command I need to send to some background window(I known the related VB function), but it will only work when the window is active. If the window is really active, I cant do anything in the foreground.

So is it there anyway to mock the window to active state?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes there is, see this example

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

if you want to minimize that window you can send keystrokes to do that, but this is language dependent so first try them manually. The following sends the keystrokes Alt (%) space and N from miNimize. Try in your window to push the Alt-Space keys to get the menu that controls this

oShell.SendKeys "(% )N" 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...