Created
May 26, 2023 17:38
-
-
Save puppis42/0429d1d06c602e8e13a76e1d60dea9f1 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Security.Policy; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace scrn | |
{ | |
public partial class Form1 : Form | |
{ | |
[DllImport("user32.dll")] | |
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); | |
[DllImport("user32.dll")] | |
static extern void mouse_event(Int32 dwFlags, Int32 dx, Int32 dy, Int32 dwData, UIntPtr dwExtraInfo); | |
private const int WmSyscommand = 0x0112; | |
private const int ScMonitorpower = 0xF170; | |
private const int MonitorShutoff = 2; | |
private const int MouseeventfMove = 0x0001; | |
public static void MonitorOff(IntPtr handle) | |
{ | |
SendMessage(handle, WmSyscommand, (IntPtr)ScMonitorpower, (IntPtr)MonitorShutoff); | |
} | |
private static void MonitorOn() | |
{ | |
mouse_event(MouseeventfMove, 0, 1, 0, UIntPtr.Zero); | |
Thread.Sleep(40); | |
mouse_event(MouseeventfMove, 0, -1, 0, UIntPtr.Zero); | |
} | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
var form = new Form(); | |
while (true) | |
{ | |
Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50); | |
MonitorOff(form.Handle); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment