Skip to content

Instantly share code, notes, and snippets.

@rsmahmud
Created March 17, 2017 20:15
Show Gist options
  • Save rsmahmud/443fbe660f0af42277b5135dec4b4aa7 to your computer and use it in GitHub Desktop.
Save rsmahmud/443fbe660f0af42277b5135dec4b4aa7 to your computer and use it in GitHub Desktop.
getch() function from conio.h library implementation on Windows
#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