# HG changeset patch # User reimar # Date 1267316641 0 # Node ID 25090c2eb0e255b2cfb0419c88849386d4cb0966 # Parent 3cf4f49c2e87f665c8f5e72f707e484f2a409f17 Add support for reading key events from MinGW xterm. Unfortunately keys only arrive after enter was pressed and SetNamedPipeHandleState does not seem to help. diff -r 3cf4f49c2e87 -r 25090c2eb0e2 osdep/getch2-win.c --- a/osdep/getch2-win.c Sun Feb 28 00:23:58 2010 +0000 +++ b/osdep/getch2-win.c Sun Feb 28 00:24:01 2010 +0000 @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include "keycodes.h" @@ -64,7 +65,15 @@ INPUT_RECORD eventbuffer[128]; DWORD retval; int i=0; - if(!getch2_status)return -1; + if(!getch2_status){ + // supports e.g. MinGW xterm, unfortunately keys are only received after + // enter was pressed. + uint8_t c; + if (!PeekNamedPipe(in, NULL, 1, &retval, NULL, NULL) || !retval) + return -1; + ReadFile(in, &c, 1, &retval, NULL); + return retval == 1 ? c : -1; + } /*check if there are input events*/ if(!GetNumberOfConsoleInputEvents(in,&retval)) {