So bassically now I have a coninutous loop. But what I am trying to do is find a way to create a listener in PS to kick off the script to identify the application each time and only when the active window/application in the forground changes.
Any help would be apreciated
what I have:::
for (($i = 0))
{
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
$a = [tricks]::GetForegroundWindow()
$WH = get-process | ? { $_.mainwindowhandle -eq $a }
echo $WH
Start-Sleep 5
}
and bassically what i want but have no clue as to accomplish this in Powershell. I made it for my chrome extension for active tab changes, now just need to figure it out for windows app changes. If at all possible
eg. listener for when active windows changes
{
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
$a = [tricks]::GetForegroundWindow()
$WH = get-process | ? { $_.mainwindowhandle -eq $a }
echo $WH
}