From owner-freebsd-hackers Wed Jun 25 09:29:34 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id JAA01417 for hackers-outgoing; Wed, 25 Jun 1997 09:29:34 -0700 (PDT) Received: from hwcn.org (main.hwcn.org [199.212.94.65]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id JAA01411 for ; Wed, 25 Jun 1997 09:29:30 -0700 (PDT) Received: from james.freenet.hamilton.on.ca (ac199@james.hwcn.org [199.212.94.66]) by hwcn.org (8.8.6/8.8.6) with ESMTP id MAA25273; Wed, 25 Jun 1997 12:29:48 -0400 (EDT) Received: from localhost (ac199@localhost) by james.freenet.hamilton.on.ca (8.8.6/8.8.6) with SMTP id MAA24128; Wed, 25 Jun 1997 12:29:58 -0400 (EDT) X-Authentication-Warning: james.freenet.hamilton.on.ca: ac199 owned process doing -bs Date: Wed, 25 Jun 1997 12:29:58 -0400 (EDT) From: Tim Vanderhoek X-Sender: ac199@james.freenet.hamilton.on.ca Reply-To: Tim Vanderhoek To: MARK SAYER cc: "'freebsd-hackers@freebsd.org'" Subject: RE: BSD io In-Reply-To: <199706250208.TAA23288@hub.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by hub.freebsd.org id JAA01413 Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Wed, 25 Jun 1997, MARK SAYER wrote: > I have been looking for this for ages. I resorted to using ncurses, but > then I was stuck with using ncurses window management (yuk). So, I tried > the code below and it doesn't seem to work as promised. I just want the > program to trap 1 keypress and continue execution. Ok, that's what it will do... Alternatively, you twiddle it such that getchar() returns immediately regardless of wether there's input available or not (although I don't know what return value it uses in the latter case). > #include > #include > > struct termios old, new; > > main() > { > char c; Since I see J'oerg read this, I'm surprised he didn't beat-up on you for not making this an int c;... :) (It's better as an int, of course) > tcgetattr (fileno(stdin), &old); new = old; > > new.c_iflag &=~(ICANON|ECHO); It doesn't help that you changed the above from new.c_lflag &= to new.c_iflag &= ... > tcsetattr (fileno(stdin), TCSANOW, &new); > > c = getc(stdin); > > tcsetattr (fileno(stdin), TCSANOW, &old); > } > All it seems to do is stop trapping my CR key?? That's because c_iflag controls, what you used, is for input flags, but c_lflag is for local flags, what I used in the code you tried to copy. :) Additionally, there're also c_cflags, c_oflags for control and ouput options, respectively. termios(4) lists all the flags. Various /usr/include/* files also describe some. > 168: {9} ./a.out > > a^M^M^M^Mò Disabling IEXTEN won't really solve your problem. Just change c_iflags to c_lflags... > Any ideas? Yes. See above. -- Outnumbered? Maybe. Outspoken? Never! tIM...HOEk