Last active
May 10, 2020 00:57
-
-
Save AndrewPardoe/944957cc9da0f0d9604b117e7963037d to your computer and use it in GitHub Desktop.
Temporarily prevent Windows machine from sleeping, allows monitors to turn off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma comment(lib, "Kernel32") | |
#include <conio.h> | |
#include <Windows.h> | |
#include <WinBase.h> | |
int main() | |
{ | |
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED); | |
_cputs("System state set to not sleep.\nPress `t` to revert state and terminate.\n"); | |
char c; | |
do { | |
c = toupper(_getch()); | |
} | |
while (c != 'T'); | |
SetThreadExecutionState(ES_CONTINUOUS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment