ReactOS  0.4.14-dev-831-gef8c9239
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 }
int char_avail
Definition: ungetch.c:15
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
FILE * stdin
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
unsigned int BOOL
Definition: ntddk_ex.h:94
int ungot_char
Definition: ungetch.c:16
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
smooth NULL
Definition: ftsmooth.c:416
const GLubyte * c
Definition: glext.h:8905
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
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:1197
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
int _file
Definition: mbstring.h:24
#define c
Definition: ke_i.h:80

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