home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!sangam!shakti!saathi.ncst.ernet.in!howard
- From: howard@saathi.ncst.ernet.in (Howard D'Souza)
- Subject: Re: Keyboard hit in C programs
- Message-ID: <BxLpHJ.J5A@shakti.ncst.ernet.in>
- Keywords: Keyboard hit, C programs, UNIX
- Sender: news@shakti.ncst.ernet.in (News account)
- Organization: National Centre for Software Technology, Bombay, India.
- References: <1dms9iINNa6m@agate.berkeley.edu> <1992Nov10.155417@rbg.informatik.th-darmstadt.de>
- Date: Thu, 12 Nov 1992 11:34:31 GMT
- Lines: 48
-
- In article <1992Nov10.155417@rbg.informatik.th-darmstadt.de> misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
- >In article <1dms9iINNa6m@agate.berkeley.edu>, bernt@valois (Bernt Skottun) writes:
- >>
- >> I am in the process of adapting a C program from the PC for
- >> the UNIX environment (for SUN 3 running SUNOS 4.1.1).
- >> In this program it is essential that
- >> the user be able to stop certain parts of the program
- >> (e.g. an inner loop) by hitting the keyboard (any key
- >> is fine) while as long as the keyboard is not touched the execution
- >> of the program will continue un-interupted (thus a procedure
- >> which requires, or expects, the user to type in a key stroke at certain
- >> intervals will not do). In the DOS environment
- >> I have been able to do this with the "kbhit()" function.
- >> My question is: what is the equivalent function in the UNIX
- >> environment? or how does one go about creating such a function?
- >> Any suggestions will be very welcome. Thanks a lot.
- >> Bernt Skottun, bernt@valois.berkeley.edu
- >>
- >
- >Ok, since ^C is an 'any key' you only have to catch the SIGINT you
- >get if ^C is hit.
- >
-
- Obviously, by "any key" Bernt Skottun means any key that the user wishes to
- hit and not one that the program wants him to. For this kind of thing, the
- CBREAK mode for the tty immediately suggests itself. (Check out the sg_flags
- field of the sgttyb structure for ioctl(2) called with TIOCSETP). If the
- program does not wish to wait till the user hits the key, select(2) could be
- used (if available) or the terminal could be put in non-blocking mode ( by
- setting the O_NDELAY status flag for the tty's descriptor using fcntl(2).
-
-
- >In function() ( prototyped as void function(void) ) the first call should
- >be signal(SIGINT,function) because the behavior of SIGINT is reset to default
- >by the signal-handler.
-
- What version of UNIX are you using, may I ask? And isn't it time you treated
- yourself to an update? :)
-
- Howard
-
-
-
-
-
-
- Howard M. D'Souza
- National Centre For Software Technology, Graphics Division
-