I want to stop my monitor to stop sleep (which is driven by company policies). Below is the code I am using for that
while (true)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
Cursor.Clip = new Rectangle(this.Location, this.Size);
System.Threading.Thread.Sleep(2000);
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X + 50, Cursor.Position.Y + 50);
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
I can see mouse moving without While loop. But with while it moves mouse only once and then it restrict the mouse to move to right side.
Is there any better way to do it?
This method moves the mouse by 1 pixel every 4 minutes and it will not let your monitor to sleep.
If you want to keep your computer awake, dont move the mouse, just tell your program that computer must keep awake. Moving the mouse is a very bad practice.
and then, just call
ForceSystemAwake()
when you want to keep awake your computer, then callResetSystemDefault()
when you have finish