Xref: utzoo comp.unix.programmer:191 comp.unix.questions:26008 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!unisoft!rembo From: rembo@unisoft.UUCP (Tony Rems) Newsgroups: comp.unix.programmer,comp.unix.questions Subject: Re: can i test for keyboard input? Keywords: select ioctl Message-ID: <3151@unisoft.UUCP> Date: 5 Oct 90 22:53:20 GMT References: <1990Oct3.041737.2280@watmath.waterloo.edu> Reply-To: rembo@unisoft.UUCP (Tony Rems) Lines: 37 In article <1990Oct3.041737.2280@watmath.waterloo.edu> mwnewman@watmsg.uwaterloo.ca (mike newman) writes: >I would like to be able to respond dynamically to keyboard input >(without doing getchar and waiting for the user to type something) by >either: > > 1) Having some kind of interrupt routine that will be called > every time a key is pressed. > > 2) Calling some OS routine that returns TRUE/FALSE if there > is/isn't any keyboard input waiting. I know my little ol' ST > at home (bless it's heart :-) has such a call: does unix? > > 3) Any other way :-). > >This seems like it should be possible: musn't the shell do something >along these lines to handle type ahead? (???) > >Please email replies: if there is interest, I will post a summary. > I think what you are looking for is the select(2) routine. It will allow you to open your tty and it will wait until there is data available to be read, so it will return as soon as the user types something. Another solution would be to set your terminal into cbreak mode and this way input will come to your program without being buffered. You can do this with ioctl(2). This differs depending on whether you are using BSD or SYS V. Final, if you want to get fancy, you can look into pseudo-ttys or curses. All these should be in your manual set. If you can't find what you're looking for with these calls let me know and I'll send you some sample code. -Tony