What you are trying to do won't work this way. Sorry.
Google around things like "msdn SetWindowsHookEx" and "msdn KeyboardProc". You will need to put the hook procedure in a DLL.
Make sure you screensave on a unique key
sequence. Activating the screensaver with just an
Esc key press is bound to interact badly. (Many other applications use the Escape key for valid reasons.)
To activate the user's current screensaver (the one he has selected from the Control Panel "Desktop Properties" applet), you should use the following code:
1 2 3 4 5 6 7 8 9 10
|
#include <windows.h>
bool ActivateScreenSaver()
{
BOOL b;
if (SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0, (PVOID)&b, 0 )) return false;
if (!b) return false;
PostMessage( GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0 );
return true;
}
|
The result is whether or not the screensaver was successfully activated (except for
very rare and unlikely failures).
Long ago I wrote a utility (that I still use) called
Mr. Sandman that activates the screensaver. (It doesn't use hooks though -- it was purposefully designed to be a 'click-to-activate' function rather than the more common 'move-mouse-to-screen-corner-to-activate' hook type.) PM me if you want the (Delphi) code.
Hope this helps.