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.
public class PowerHelper
{
public static void ForceSystemAwake()
{
NativeMethods.SetThreadExecutionState(NativeMethods.EXECUTION_STATE.ES_CONTINUOUS |
NativeMethods.EXECUTION_STATE.ES_DISPLAY_REQUIRED |
NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED |
NativeMethods.EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
}
public static void ResetSystemDefault()
{
NativeMethods.SetThreadExecutionState(NativeMethods.EXECUTION_STATE.ES_CONTINUOUS);
}
}
internal static partial class NativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
[FlagsAttribute]
public enum EXECUTION_STATE : uint
{
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
// Legacy flag, should not be used.
// ES_USER_PRESENT = 0x00000004
}
}
and then, just call ForceSystemAwake()
when you want to keep awake your computer, then call ResetSystemDefault()
when you have finish