title: raw input mode on stdin in Cygwin/Mintty
body: <p>I want to get my stdin into raw input mode in Cygwin/Mintty. How do I do that? Right now, it is line-buffered. With raw input mode, I mean that <code>read</code> returns on every single entered character.</p>
  
  <p>I would prefer to do that without any further dependencies. I.e. I guess this probably can be done by linking against some libs from Cygwin, however, if it is possible, I'd like to avoid that.</p>
  
  <p>Some search results: <a href="https://github.com/joyent/libuv/issues/358" rel="nofollow">libuv issue</a>, <a href="https://github.com/joyent/libuv/blob/master/src/win/tty.c" rel="nofollow">libuv win/tty.c</a>, <a href="https://github.com/scottt/cygwin-vmci-sockets/blob/master/winsup/cygwin/tty.cc" rel="nofollow">Cygwin tty.cc</a>, <a href="https://github.com/openunix/cygwin/blob/master/winsup/cygwin/fhandler_tty.cc" rel="nofollow">Cygwin fhandler_tty.cc</a>, <a href="http://cygwin.com/ml/cygwin/2012-05/msg00298.html" rel="nofollow">Cygwin post (non-blocking stdin)</a>, <a href="https://code.google.com/p/mintty/issues/detail?id=56" rel="nofollow">Mintty issue</a>, <a href="https://code.google.com/p/msysgit/issues/detail?id=29" rel="nofollow">Msysgit issue</a></p>
  
  <p>I tried via <code>SetConsoleMode</code>, but that only works for the Windows console, not for Mintty. I.e. this code:</p>
  
  <pre><code>    // Setting terminal to raw mode...
      HANDLE hStdin;
      DWORD mode;
      //hStdin = GetStdHandle(STD_INPUT_HANDLE);
      hStdin = (HANDLE) _get_osfhandle(STDIN_FILENO);
  
      if (GetFileType(hStdin) == FILE_TYPE_CHAR) {
          cout &lt;&lt; "stdin is file type char" &lt;&lt; endl;
          GetConsoleMode(hStdin, &amp;mode);
          if (
              !SetConsoleMode(
                  hStdin,
                  mode &amp; ~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT))
          ) {
              cerr &lt;&lt; "Cannot set stdin to raw mode" &lt;&lt; endl;
              // ignore...
          }
      }
  </code></pre>