ReactOS 0.4.15-dev-7918-g2a2556c
getch.c File Reference
#include <precomp.h>
Include dependency graph for getch.c:

Go to the source code of this file.

Functions

int _getch (void)
 

Function Documentation

◆ _getch()

int _getch ( void  )

Definition at line 16 of file getch.c.

17{
18 DWORD NumberOfCharsRead = 0;
19 char c;
20 HANDLE ConsoleHandle;
21 BOOL RestoreMode;
22 DWORD ConsoleMode;
23
24 if (char_avail) {
25 c = ungot_char;
26 char_avail = 0;
27 } else {
28 /*
29 * _getch() is documented to NOT echo characters. Testing shows it
30 * doesn't wait for a CR either. So we need to switch off
31 * ENABLE_ECHO_INPUT and ENABLE_LINE_INPUT if they're currently
32 * switched on.
33 */
34 ConsoleHandle = (HANDLE) _get_osfhandle(stdin->_file);
35 RestoreMode = GetConsoleMode(ConsoleHandle, &ConsoleMode) &&
36 (0 != (ConsoleMode &
38 if (RestoreMode) {
39 SetConsoleMode(ConsoleHandle,
40 ConsoleMode & (~ (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)));
41 }
43 &c,
44 1,
45 &NumberOfCharsRead,
46 NULL);
47 if (RestoreMode) {
48 SetConsoleMode(ConsoleHandle, ConsoleMode);
49 }
50 }
51 if (c == 10)
52 c = 13;
53 return c;
54}
#define NULL
Definition: types.h:112
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleA(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
Definition: readwrite.c:1195
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLubyte * c
Definition: glext.h:8905
#define stdin
Definition: stdio.h:98
#define c
Definition: ke_i.h:80
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
PVOID HANDLE
Definition: typedefs.h:73
int char_avail
Definition: ungetch.c:15
int ungot_char
Definition: ungetch.c:16
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define ENABLE_LINE_INPUT
Definition: wincon.h:79

Referenced by _cgets(), _getche(), _tmain(), abort(), DumpFont(), GetPass(), gl_getc(), gl_getcx(), gl_getpass(), main(), MainUsage(), PrintHelp(), ShowAppList(), TestEventsGeneration(), Wait(), and wmain().