我有以下用于PowerShell的代码:
$wshell = New-Object -ComObject WScript.Shell;
$code = @'
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
'@
Add-Type $code -Name Utils -Namespace Win32
while (1 -eq 1) {
Sleep 50; # Interval (in seconds) between switch
$wshell.AppActivate('Opera');
$wshell.SendKeys('^{PGUP}'); # Ctrl + Page Up keyboard shortcut to switch tab
$wshell.SendKeys('{F5}'); # F5 to refresh active page
Start-Sleep -Milliseconds 100
$wshell.AppActivate('chrome');
}
应该每隔50秒钟刷新和循环一次Opera选项卡,然后重新将注意力集中在打开的应用程序上(我工作的地方)。它运行良好,但对于Chrome浏览器来说它是静态的,我需要加载打开的应用,刷新后重新获得焦点以打开应用。