让App成为焦点

问题描述 投票:1回答:1

我使用wscript在我的机器上启动一个应用程序。然后我杀了它之前使用这个应用程序30秒。我这样做使用python -

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

我想知道是否有可能确保启动的应用程序收到SendKeys指令,而不是我可能会在30秒内意外关注的另一个应用程序。

谢谢,

巴里。

wsh
1个回答
0
投票

问题

  • 如何保证wsh脚本SendKeys事件进入特定目标应用程序

解决方法

  • 代替使用SendKeys定位特定进程的直接解决方案,您可以使用ShellRun的“等待”变体

  • 将“之前”改为“之后”

Before

WshShell.Run(run_name)

After

WshShell.Run(run_name,1,true)

© www.soinside.com 2019 - 2024. All rights reserved.