This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Character at a time input (was Re: Where is less source?)

Don't know about ioctl, but termios will do it.  I've included a
simple program that shows it working.

If you're planning on detecting arrow keys, function keys, etc., then
you have to remember that they produce an escape-sequence of several
characters, which you'll have to detect and decode.

Hope this helps,


#include <unistd.h>
#include <stdio.h>
#include <termios.h>

main (void)
  struct termios new_settings;
  struct termios stored_settings;
  char c;

  /* record the old settings to restore the terminal when finished */
  tcgetattr (0, &stored_settings);
  new_settings = stored_settings;

  /* set things up for character-at-a-time */
  new_settings.c_lflag &= ~(ICANON | ECHO);
  new_settings.c_cc[VTIME] = 0; /* don't think this is relevant if VMIN=1 */
  new_settings.c_cc[VMIN] = 1;
  tcsetattr (0, TCSANOW, &new_settings);

  /* main loop - press q to exit */
      c = getchar ();
      printf ("%d\t%c\n", c, c);
  while (c != 'q');

  /* restore the old settings */
  tcsetattr (0, TCSANOW, &stored_settings);
  return 1;

> -----Original Message-----
> From: J. Scott Edwards []
> Sent: 22 August 2002 23:23
> To: Gerrit @ cygwin
> Thanks, I found it.  But unfortunately it didn't answer my question:
> Can ioctl be used to change the standard input into character 
> at a time
> mode or do I have to use ncurses or is there a better way to 
> just get a
> character at a time?

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]