开发者

Keep App in Focus

I use wscript to l开发者_运维知识库aunch an application on my machine. I then use this app for 30 seconds before I kill it. I do this using python -

import win32com.client
import time
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("My App")
time.sleep(0.5)
shell.SendKeys('%f')
...

I was wondering if it is possible to ensure that the launched app receives the SendKeys instructions and not another app that I might accidentally give focus to under this 30 second period.

Thanks,

Barry.


Problem

  • how to guarantee a wsh script SendKeys event goes to a specifically targted application

Workaround

  • in lieu of a straightforward solution to targeting a specific process with SendKeys you can use the "wait" variant of ShellRun

Example

  • Change "Before" into "After"

Before

WshShell.Run(run_name)

After

WshShell.Run(run_name,1,true)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜