[ros-diffs] [gvg] 17904: _getch() doesn't echo the chars it retrieves and operates in raw mode.

gvg at svn.reactos.com gvg at svn.reactos.com
Sun Sep 18 00:34:02 CEST 2005


_getch() doesn't echo the chars it retrieves and operates in raw mode.
Modified: trunk/reactos/lib/crt/conio/getch.c
  _____  

Modified: trunk/reactos/lib/crt/conio/getch.c
--- trunk/reactos/lib/crt/conio/getch.c	2005-09-17 22:00:35 UTC (rev
17903)
+++ trunk/reactos/lib/crt/conio/getch.c	2005-09-17 22:33:53 UTC (rev
17904)
@@ -20,21 +20,41 @@

  */
 int _getch(void)
 {
-    DWORD  NumberOfCharsRead = 0;
+    DWORD NumberOfCharsRead = 0;
     char c;
+    HANDLE ConsoleHandle;
+    BOOL RestoreMode;
+    DWORD ConsoleMode;
+
     if (char_avail) {
         c = ungot_char;
         char_avail = 0;
     } else {
+        /*
+         * _getch() is documented to NOT echo characters. Testing shows
it
+         * doesn't wait for a CR either. So we need to switch off
+         * ENABLE_ECHO_INPUT and ENABLE_LINE_INPUT if they're currently
+         * switched on.
+         */
+        ConsoleHandle = (HANDLE) _get_osfhandle(stdin->_file);
+        RestoreMode = GetConsoleMode(ConsoleHandle, &ConsoleMode) &&
+                      (0 != (ConsoleMode &
+                             (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)));
+        if (RestoreMode) {
+            SetConsoleMode(ConsoleHandle,
+                           ConsoleMode & (~ (ENABLE_ECHO_INPUT |
ENABLE_LINE_INPUT)));
+        }
         ReadConsoleA((HANDLE)_get_osfhandle(stdin->_file),
 		             &c,
 		             1,
 		             &NumberOfCharsRead,
 		             NULL);
+        if (RestoreMode) {
+            SetConsoleMode(ConsoleHandle, ConsoleMode);
+        }
     }
     if (c == 10)
         c = 13;
-    putchar(c);
     return c;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.reactos.org/pipermail/ros-diffs/attachments/20050918/562388b9/attachment.html


More information about the Ros-diffs mailing list