Unix, C, and C++
Function Reference
Asynchronous Keyboard Input

This will not even come close to compiling under windows. The simplest and ugliest solution is to surround all the function definitions with "#ifdef unix" and "#endif"

example

#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>

termios saved_termios;
int ttysavefd=-1;
int savedflags=0;
char ttystate='L';
int ready=0;
int thecharacter=0;
int control_c_pending=0;

void sigio(int x)
{ int n=read(0, &thecharacter, 1);
  if (n!=-1) 
    ready=1; }

void sigint(int x)
{ if (control_c_pending)
    exit(1);
  thecharacter=3;
  control_c_pending=1;
  ready=1; }

int tty_cbreak(int fd)
{ termios buf;
  if (tcgetattr(fd, &saved_termios)<0) return 0;
  buf=saved_termios;
  buf.c_lflag &= ~(ECHO | ICANON);
  buf.c_cc[VMIN]=1;
  buf.c_cc[VTIME]=0;
  if (tcsetattr(fd, TCSAFLUSH, &buf)<0) return 0;
  ttystate='C';
  ttysavefd=fd;
  signal(SIGIO, sigio);
  signal(SIGINT, sigint);
  int pid=getpid();
  int flags=fcntl(0, F_GETFL, 0);
  fcntl(0, F_SETFL, flags | O_ASYNC | O_NONBLOCK );
  fcntl(0, F_SETOWN, pid);
  return 1; }

int tty_reset(int fd)
{ if (ttystate=='L')
    return 1;
  if (tcsetattr(fd, TCSAFLUSH, &saved_termios)<0)
    return 0;
  ttystate='L';
  signal(SIGIO, SIG_IGN);
  signal(SIGINT, SIG_DFL);
  fcntl(0, F_SETFL, savedflags);
  return 1; }

void tty_atexit(void)
{ if (ttystate!='L')
    tty_reset(ttysavefd); }

void main(void)
{ atexit(tty_atexit);
  int ok=tty_cbreak(0);
  printf("get on with it.\n");
  while (1)
  { usleep(1000);
    if (ready)
    { if (thecharacter==3)
      { printf("control-C\n");
        /* control_c_pending=0; */ }
      else
        printf("Character with ASCII code %d\n", thecharacter);
      ready=0; } }
  tty_reset(0);
  printf("All done.\n"); }