home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!pmafire!news.dell.com!natinst.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: Keyboard hit in C programs
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Nov10.155417@rbg.informatik.th-darmstadt.de>
- Date: Tue, 10 Nov 1992 14:54:17 GMT
- References: <1dms9iINNa6m@agate.berkeley.edu>
- Nntp-Posting-Host: rbhp69.rbg.informatik.th-darmstadt.de
- Organization: TU Darmstadt
- Keywords: Keyboard hit, C programs, UNIX
- Lines: 29
-
- 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.
-
- #include <signal.h>
- signal(SIGINT,function)
-
- 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.
-
- Walter
-