Long time ago I used Applesoft BASIC on the Apple //c, BASIC was a very limited language but it provided a lot of very interesting high level functions.

For example the GET function, GET was like INPUT except that it only waits for one character, and returns immediately on getting that without printing it to the screen. Thus, 'GET A$' is an excellent way of waiting for any key, or building a better INPUT.

Using Linux with the C languange this function could be very useful specially on command line programs, so I wrote an equivalent function that I named inKey.

The inKey function accept 2 parameters, the first one enable or disable the output, for example if you want that the pressed key will be showed you shall pass the ENABLE value as the first parameter of the function. The second parameter says to the function to flush or not  the pre-existing buffered input before wait for a character.

/*+--------------------------------------------------------------+
  |             inKey.c  -  description                          |
  |                -------------------                           |
  | begin      : 03/06/2006 10.21                                |
  | copyright  : (C) 2006 xAppSoftware                           |
  | author     : Luigi D'Andrea                                  |
  | email      : luigi.dandrea@xappsoftware.com                  |
  | compiling  : gcc -c inKey.c                                  |
  |                                                              |
  | Latest version on http://www.xappsoftware.com                |
  +--------------------------------------------------------------+
  | inKey library may be redistributed and modified under certain|
  | conditions. This software is distributed on an "AS IS" basis |
  | WITHOUT WARRANTY OF ANY KIND, either express or implied.     |
  | See the file License.txt for details.                        |
  +--------------------------------------------------------------+*/

/*+--------------------------------------------------------------+
  | SYSTEM INCLUDES                                              |
  +--------------------------------------------------------------+*/
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>

/*+--------------------------------------------------------------+
  | SPECIFIC INCLUDES                                            |
  +--------------------------------------------------------------+*/
#include "inKey.h"

/*+--------------------------------------------------------------+
  | Function name : inKey                                        |
  | Parameters    :                                              |
  |      output   :  enable or disable the output                |
  |                  OUTPUT_ENABLE or OUTPUT_DISABLE             |
  |      flushing :  flushing or not pre-existing buffered       |
  |                  input before blocking                       |
  |                  FLUSHING_ON or FLUSHING_OFF                 |
  +--------------------------------------------------------------+*/

int inKey(int output, int flushing)
{
	char                  ch;
	int                   error;
	static struct termios Otty, Ntty;
	int                   flag;

	fflush(stdout);
	tcgetattr(0, &Otty);                   /* Stores current settings in Otty. */
	Ntty                =  Otty;
	Ntty.c_iflag        =  0;              /* input mode                       */
	Ntty.c_oflag        =  0;              /* output mode                      */
	Ntty.c_lflag        &= ~ICANON;        /* line settings                    */

	if(output==O_DISABLE)
		Ntty.c_lflag    &= ~ECHO;      /* disable echo                     */
	else
		Ntty.c_lflag    |=  ECHO;      /* enable echo                      */
	Ntty.c_cc[VMIN]      =  CMIN;          /* minimum chars to wait for        */
	Ntty.c_cc[VTIME]     =  CTIME;         /* minimum wait time                */
	if(FLUSHING_ON==flushing)
		flag = 	TCSAFLUSH;
	else
		flag =  TCSANOW;
	if (0 == (error = tcsetattr(0, flag, &Ntty)))
	{
		error  = read(fileno(stdin), &ch, 1 ); /* get char from stdin   */
		error += tcsetattr(0, flag, &Otty);    /* restore old settings  */
	}
	if(1==error)
	{
	    return((int)ch);
	}
	else
	{
	    return(-1);
	}
}

You can find the full packet with headers and makefile here. In this packet you will find also the project directory for codeblocks.