Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Rotate through specific windows every 5 seconds

Description
This script will rotate focus to the windows specified in the windowTitles array every 5 seconds. You can adjust the rotation time with the rotationTimeMS variable. The script will loop forever, exit it using the tray icon.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
May 6, 2024
Date Last Modified
May 6, 2024

Scripted Function (Macro) Code

using System;
using System.Collections.Generic;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run()
	{
		// Set the window titles here
		string[] windowTitles = {"Word", "PowerPoint", "Excel"};
		
		// Set the rotation time in milliseconds
		uint rotationTimeMS = 5000;
		
		// Do a sanity check on the rotation time and exit if it's too low
		if (rotationTimeMS < 5000)
		{
			BFS.Dialog.ShowMessageError("Your rotation time is less than 5 seconds, this will make it difficult to exit the script. Exiting now.");
			return;
		}
		
		// Find all of the windows and put them in a list
		List<IntPtr> foundWindows = new List<IntPtr>();
		foreach (IntPtr window in BFS.Window.GetVisibleAndMinimizedWindowHandles())
		{
			foreach (string windowTitle in windowTitles)
			{
				if (BFS.Window.GetText(window).ToLower().Contains(windowTitle.ToLower()))
				{
					foundWindows.Add(window);
				}
			}
		}
		
		// Exit if no windows found
		if (foundWindows.Count == 0)
		{
			BFS.Dialog.ShowMessageError("No windows found that match the titles. Exiting");
			return;
		}
		
		// Rotate through them
		int i = 0;
		while (true)
		{
			BFS.Window.Focus(foundWindows[i]);
			i++;
			// Reset the index when we're at the end of the foundWindows array
			if (i == foundWindows.Count)
			{
				i = 0;	
			}
			BFS.General.ThreadWait(rotationTimeMS);	
		}
	}
}