1- #include <Windows.h>
1+ #include <Windows.h>
22#include <process.h>
33#include <stdint.h>
44#include <stdio.h>
@@ -44,6 +44,7 @@ static HRESULT CreatePseudoConsoleAndPipes(HPCON* hpcon, Context* ctx);
4444static HRESULT InitializeStartupInfoAttachedToPseudoConsole (STARTUPINFOEXA * startupInfo ,
4545 HPCON hpcon );
4646static void __cdecl PipeListener (LPVOID );
47+ static void __cdecl InputHandlerThread (LPVOID );
4748
4849int main (int argc , const char * argv []) {
4950 Context ctx ;
@@ -83,6 +84,9 @@ int main(int argc, const char* argv[]) {
8384
8485 if (S_OK == hr ) {
8586 ctx .events [1 ] = cmdProc .hThread ;
87+
88+ HANDLE inputHandler = (HANDLE ) _beginthread (InputHandlerThread , 0 , & ctx );
89+
8690 WaitForMultipleObjects (sizeof (ctx .events ) / sizeof (HANDLE ), ctx .events , FALSE,
8791 INFINITE );
8892 }
@@ -356,3 +360,27 @@ static void WritePass(Context* ctx) {
356360 } break ;
357361 }
358362}
363+
364+ static void __cdecl InputHandlerThread (LPVOID arg ) {
365+ Context * ctx = arg ;
366+ HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE );
367+ DWORD mode ;
368+
369+ GetConsoleMode (hStdin , & mode );
370+ SetConsoleMode (hStdin , (mode & ~ENABLE_LINE_INPUT ) & ~ENABLE_ECHO_INPUT );
371+
372+ char buffer ;
373+ DWORD bytesRead , bytesWritten ;
374+
375+ while (1 ) {
376+ if (!ReadFile (hStdin , & buffer , 1 , & bytesRead , NULL ) || bytesRead == 0 ) {
377+ break ;
378+ }
379+
380+ if (!WriteFile (ctx -> pipeOut , & buffer , 1 , & bytesWritten , NULL )) {
381+ break ;
382+ }
383+ }
384+
385+ SetConsoleMode (hStdin , mode );
386+ }
0 commit comments