You can use UI Automation API to do this.
First add two references: UIAutomationClient and UIAutomationTypes, they are generally located in:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8
The version depends on which version you have installed.
Then, you can use the following code to detect whether the slide is in focus.
static void Main(string[] args)
{
Automation.AddAutomationFocusChangedEventHandler(OnFocusChangedHandler);
Console.ReadLine();
}
private static void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args)
{
AutomationElement element = src as AutomationElement;
if (element != null)
{
try
{
string name = element.Current.Name;
string id = element.Current.AutomationId;
int processId = element.Current.ProcessId;
using (Process process = Process.GetProcessById(processId))
{
if (name.Contains("Slide"))
{
Console.WriteLine(process.MainWindowTitle);
Console.WriteLine(" Name: {0}, Id: {1}, Process: {2}", name, id, process.ProcessName);
}
}
}
catch (ElementNotAvailableException)
{
Console.WriteLine("this app has closed");
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.