如何解决Powershell 将 f5 键发送到边缘
我正在尝试创建一个刷新边缘的脚本:
start microsoft-edge:https://login.salesforce.com/?locale=eu
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Microsoft Edge')
while ($true)
{
Sleep 15
$wshell.SendKeys('{f5}')
}
问题是它发送 F5 到我所在的窗口,例如如果我在记事本中它会按 f5 它会创建时间戳,我希望它只发送到边缘,有什么办法可以解决吗?
解决方法
以下代码片段可以完成这项工作。您需要告诉哪个窗口应该被激活,例如a s 如下:
$medge = Start-Process -PassThru -FilePath microsoft-edge:https://login.salesforce.com/?locale=eu
$wshell = New-Object -ComObject wscript.shell
Start-Sleep -Seconds 15 ### increase time for slow connection
while ( $wshell.AppActivate($medge.Id) ) ### activate the desired window
{
$wshell.SendKeys('{f5}') ### send keys only if successfully activated
Start-Sleep -Seconds 15
}
以上代码片段(源自相关代码片段)每 15 秒刷新一次 microsoft-edge。
时机很重要:
- 授予 microsoft-edge 足够的时间来运行和建立连接(参见
Start-Sleep
beforeAppActivate
),以及 - 在窗口激活后立即发送密钥。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。