I have programs that compile and run under MacOS and Linux. The programs use termios to get keystrokes from a terminal. I read a short string of characters from the terminal until I hit the end of the buffer or a 0.1 sec timeout between characters. This captures most escape sequences, and distinguishes between computer-generated escape sequences and human typing by the speed.
I am pretty sure there is no termios code for Windows 11. They have an equally venerable but incompatible way of handling comms of this sort. There does not seem to be a termios port for Windows, and it seems unlikely there would be. But is there a platform-independent solution for the subset I need: just grabbing key codes?
If there isn't one, it would be good to have a firm answer so I can stop looking. I can write something that does the equivalent under Windows with #defines and a compiler flag. But I would like to use existing code if it exists.
Background:
I have bought a Windows machine, and I am trying to port programs I developed under MacOS to Windows for friends and family. I am compiling under Windows for the first time in many years. My programs compile and run under a bash shell. I can compile the same code under a Windows terminal, but it currently needs termios to run.
Under the hood, most terminal programs look the same these days. The standard for escape codes and ANSI seems to have been set by xterm. The Mac and Windows terminals now seem to match.
FWIW, my termio code follows...
tcgetattr(0, &tio);
tio.c_iflag &= ~(IXON | IXOFF); // Pass Ctrl-S and Ctrl-Q
tio.c_lflag &= ~(ECHO | ICANON);
tio.c_cc[VSUSP] = 0; // Pass Ctrl-Z (confuses terminal)
tio.c_cc[VMIN] = 0;
tio.c_cc[VTIME] = 1;
tcsetattr(0, TCSANOW, &tio);