Last active
February 6, 2024 10:20
-
-
Save likecyber/c9582527042eb4596780c49946b65282 to your computer and use it in GitHub Desktop.
Disable monitor and re-enable again after moving mouse cursor. (DisplayFusion Scripted Function)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Scripted Function allows one monitor to turn off while keeping the rest on. | |
// It is recommended to install Virtual Display Driver to have dummy monitor. | |
// https://github.com/itsmikethetech/Virtual-Display-Driver | |
// Please adjust the resolution and scale according to your monitor, | |
// then create 3 seperate profiles in DisplayFusion. | |
// 1st: Only active monitor; 2nd: Only dummy monitor; 3rd: Both monitors | |
// You can create a trigger to run when idling longer than specific time. | |
using System; | |
using System.Drawing; | |
using System.Threading.Tasks; | |
public static class DisplayFusionFunction | |
{ | |
private static readonly uint originalMonitorId = 1; | |
private static readonly uint dummyMonitorId = 3; | |
private static readonly string originalProfile = "Normal"; | |
private static readonly string dummyProfile = "Dummy"; | |
private static readonly string mergeProfile = "Normal + Dummy"; | |
public static void Run(IntPtr windowHandle) | |
{ | |
if (!BFS.DisplayFusion.GetCurrentMonitorProfile().Equals(originalProfile)) | |
{ | |
return; | |
} | |
BFS.MonitorFading.Enable(); | |
BFS.DisplayFusion.RunFunctionAndWait("Save Window Positions"); | |
BFS.DisplayFusion.LoadMonitorProfile(mergeProfile); | |
IntPtr[] windows = BFS.Window.GetVisibleWindowHandlesByMonitor(originalMonitorId); | |
Task[] tasks = new Task[windows.Length]; | |
for (int i = 0; i < windows.Length; i++) | |
{ | |
var currentIndex = i; | |
tasks[currentIndex] = Task.Run(() => BFS.Window.MoveToMonitor(dummyMonitorId, windows[currentIndex])); | |
} | |
Task.WaitAll(tasks); | |
BFS.DisplayFusion.LoadMonitorProfile(dummyProfile); | |
Point originalMousePosition = new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()); | |
while (true) | |
{ | |
Point currentMousePosition = new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()); | |
if (originalMousePosition != currentMousePosition) | |
{ | |
break; | |
} | |
BFS.General.ThreadWait(250); | |
} | |
BFS.DisplayFusion.LoadMonitorProfile(mergeProfile); | |
windows = BFS.Window.GetVisibleWindowHandlesByMonitor(dummyMonitorId); | |
tasks = new Task[windows.Length]; | |
for (int i = 0; i < windows.Length; i++) | |
{ | |
var currentIndex = i; | |
tasks[currentIndex] = Task.Run(() => BFS.Window.MoveToMonitor(originalMonitorId, windows[currentIndex])); | |
} | |
Task.WaitAll(tasks); | |
BFS.DisplayFusion.LoadMonitorProfile(originalProfile); | |
BFS.DisplayFusion.RunFunctionAndWait("Restore Window Positions From Last Save"); | |
BFS.MonitorFading.Disable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment