Created
March 17, 2017 20:15
-
-
Save rsmahmud/443fbe660f0af42277b5135dec4b4aa7 to your computer and use it in GitHub Desktop.
getch() function from conio.h library implementation on Windows
This file contains 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> | |
TCHAR getch(){ | |
DWORD mode, cc; | |
HANDLE h = GetStdHandle( STD_INPUT_HANDLE ); | |
if (h == NULL) | |
return 0; // console not found | |
GetConsoleMode( h, &mode ); | |
SetConsoleMode( h, mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT) ); | |
TCHAR c = 0; | |
ReadConsole( h, &c, 1, &cc, NULL ); | |
SetConsoleMode( h, mode ); | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment