I have windows 10 64 bit,and i spend a lot of time programming behind the screen.I need to take break from time to time,and limit the screen light/radiation from colliding with my head by making the screen turn black,as if turned off.
What i am capable of doing is dropping to login screen,but i need to see it BLACK to be relieved! What am really hoping to achieve is the black screen that you get when inactive for sometime.Can i do it programmatically?
Here's the code I've had so far:
#include <Windows.h>
#define KEY_DOWN(key) ((::GetAsyncKeyState(key) & 0x80000) ? 1 : 0)
#define KEY_UP(key) ((::GetAsyncKeyState(key) & 0x80000) ? 0 : 1)
int main(void)
{
// Hide the console window
HWND hWnd;
AllocConsole();
hWnd = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(hWnd, 0);
//Press ctrl + alt + 'L' to lock / Press ctrl + 'E' to terminate the program
while (1)
{
if (::GetAsyncKeyState('L') == -32767)
{
if (KEY_DOWN(VK_CONTROL) && KEY_DOWN(VK_MENU))
LockWorkStation();
}
if (::GetAsyncKeyState('E') == -32767)
{
if (KEY_DOWN(VK_CONTROL))
return 0;
}
}
return 0;
}
Use the SC_MONITORPOWER
parameter for the WM_SYSCOMMAND
message to turn off the monitor:
SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
The argument 2
for the fourth parameter turns the monitor off.
See also https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With