views:

353

answers:

2

So my Vista machine is set to turn off it's monitors after 10 minutes. (Note : machine is not suspended, or hibernated)

I have a .Net application running, that needs to "wake" the system at a specified time. As a human, you just move the mouse or press a key. How do I do this programatically?

I've tried : programatically setting the cursor; using "SendKeys"; and even pinvoking CreateWaitableTimer to unsuspend (even though it's not suspended) in the hope that that would trigger something.

Ideally code in c# would be great, but the correct Win API would suffice.

Many thanks in advance.

+1  A: 

A stupid idea I would vote down (if I could vote my self down)

BCS
An ingenious and amazingly stupid solution at the same time :)
Mike Wagner
There is always the [simpson solution](http://en.wikipedia.org/wiki/Drinking_bird). :)
Remou
+1  A: 

You should be able to control monitor power by sending system command messages as follows. Note that this is tested on XP, Vista may have changed things somewhat so you'll need to test it and let us know.

This code is in VB but you can see the Win32 API call that it uses. You need to pass a window handle to the function so your code will need a window created to process the message (just pass it through to the default window processing function).

Const SC_MONITORPOWER As Integer = &HF170
Const WM_SYSCOMMAND As Short = &H112S
Private Function SendMessage(
    ByVal Handle As Int32,
    ByVal wMsg As Int32,
    ByVal wParam As Int32,
    ByVal lParam As Int32) As Int32
End Function
Sub MonStandBy(hWnd as Int32)
    SendMessage(hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, 1)
End Sub
Sub MonOff(hWnd as Int32)
    SendMessage(hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
End Sub
Sub MonOn(hWnd as Int32)
    SendMessage(hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
End Sub
paxdiablo
Good, a real solution!
BCS
Absolutely perfect - thanks a stack.