In any other situation simply setting the registry key
HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveActiveto 0 can work. But on a domain it's not working.
Neither does:
const int HWND_BROADCAST = 0xFFFF;
const int SC_MONITORPOWER = 0xF170;
const short WM_SYSCOMMAND = 0x112;
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);
So I began to dig which message to send in order to fake a mouse movement (or a key press) I've found the answer on this link: http://www.dreamincode.net/forums/showtopic19021.htm
After manipulating it a bit to fit my need I ended up with this code:
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
const int HWND_BROADCAST = 0xFFFF;
[Flags]
private enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
static void Main(string[] args)
{
while (true)
{
System.Threading.Thread.Sleep(1000);
mouse_event((uint)MouseEventFlags.MOVE, 0, 0, 0, 0);
}
}
It doesn't interfere with my work, CPU stays low.
This mini-program is a saver for me.
No comments:
Post a Comment