2015-08-17, 22:39
this works pretty good:
Code:
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class SFW {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
$NetflixStreaming = $false
while (1)
{
Start-Sleep -Seconds 2
$test = Get-Process -processname netflixbmc_utility*
if ($NetflixStreaming -eq $true -and $test.id -eq $null)
{
$test = Get-Process -processname chrome*
foreach($proc in $test)
{
if ($proc.mainwindowtitle.length -gt 0)
{
[SFW]::SetForegroundWindow($proc.mainwindowhandle)# activate it
[System.Windows.Forms.SendKeys]::SendWait("%{F4}") #send alt F4
}
}
$NetflixStreaming = $false
$proc = Get-Process -processname kodi*
if ($proc.id -ne $null)
{
[SFW]::SetForegroundWindow($proc.mainwindowhandle)# activate Kodi
}
}
if ($NetflixStreaming -eq $false -and $test.id -ne $null)
{
$NetflixStreaming = $true
}
}