Last active
March 18, 2018 12:49
-
-
Save hyrious/0f40d1cae92229d6411095d7b57a54e5 to your computer and use it in GitHub Desktop.
prevent sleep
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
#include <windows.h> | |
#include <stdio.h> | |
int running; | |
BOOL WINAPI consoleHandler(DWORD signal) { | |
if (signal == CTRL_C_EVENT) { | |
running = FALSE; | |
return TRUE; | |
} | |
return FALSE; | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
running = TRUE; | |
if (!SetConsoleCtrlHandler(consoleHandler, TRUE)) { | |
puts("ERROR: Could not set control handler"); | |
return 1; | |
} | |
SetThreadExecutionState(0x80000041); | |
puts("I will not sleep until you Ctrl-C."); | |
while (running && getchar() != EOF) { | |
Sleep(0); | |
} | |
SetThreadExecutionState(0x80000000); | |
puts("I'm sleepy now."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment