[CM] reading characters from keyboard in s7

Bill Schottstaedt bil at ccrma.Stanford.EDU
Thu Jul 26 10:36:45 PDT 2012

(read-char *stdin*)

will wait for you to type something in the terminal, then
return it.  There's a fancier example in s7.html (under 
begin-hook) which
watches for C-C to break out of a loop.  It uses tcgetattr
and friends; here's a stand-alone C program that is very

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

static struct termios saveit;

static int tty_reset(int fd)
  if (tcsetattr(fd, TCSAFLUSH, &saveit) < 0)

static void sigcatch(int no)

int main (int argc, char **argv)
  struct termios buf;
  int i;
  char c;

  if (signal(SIGINT, sigcatch) == SIG_ERR) exit(1);
  if (signal(SIGQUIT, sigcatch) == SIG_ERR) exit(1);
  if (signal(SIGTERM, sigcatch) == SIG_ERR) exit(1);

  if (tcgetattr(fileno(stdin), &saveit) < 0)
  buf = saveit;
  buf.c_lflag &= ~(ECHO | ICANON);
  buf.c_cc[VMIN] = 1;
  buf.c_cc[VTIME] = 0;
  if (tcsetattr(fileno(stdin), TCSAFLUSH, &buf) < 0)
  while ((i = read(fileno(stdin), &c, 1)) == 1) /* Ctrl-C to exit */
      c &= 255;
      fprintf(stderr,"got %c\n", c);

In the Snd listener, read-hook might be what you want (except it waits
for carriage-return).  To do something fancier in the listener would
probably require hacking the XmNmodifyVerify callback (in Motif)
or its equivalent in gtk as applied to the listener text widget.
snd-motif.scm has some code that might give you a start.

More information about the Cmdist mailing list