home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / wizards / 4589 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.8 KB  |  43 lines

  1. Newsgroups: comp.unix.wizards
  2. 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
  3. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  4. Subject: Re: Keyboard hit in C programs
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Nov10.155417@rbg.informatik.th-darmstadt.de>
  7. Date: Tue, 10 Nov 1992 14:54:17 GMT
  8. References:  <1dms9iINNa6m@agate.berkeley.edu>
  9. Nntp-Posting-Host: rbhp69.rbg.informatik.th-darmstadt.de
  10. Organization: TU Darmstadt
  11. Keywords: Keyboard hit, C programs, UNIX
  12. Lines: 29
  13.  
  14. In article <1dms9iINNa6m@agate.berkeley.edu>, bernt@valois (Bernt Skottun) writes:
  15. > I am in the process of adapting a C program from the PC for
  16. > the UNIX environment (for SUN 3 running SUNOS 4.1.1).
  17. > In this program it is essential that
  18. > the user be able to stop certain parts of the program
  19. > (e.g. an inner loop) by hitting the keyboard (any key
  20. > is fine) while as long as the keyboard is not touched the execution
  21. > of the program will continue un-interupted (thus a procedure
  22. > which requires, or expects, the user to type in a key stroke at certain
  23. > intervals will not do). In the DOS environment
  24. > I have been able to do this with the "kbhit()" function.
  25. > My question is: what is the equivalent function in the UNIX
  26. > environment? or how does one go about creating such a function?
  27. > Any suggestions will be very welcome. Thanks a lot.
  28. > Bernt Skottun, bernt@valois.berkeley.edu 
  29. >
  30.  
  31. Ok, since ^C is an 'any key' you only have to catch the SIGINT you
  32. get if ^C is hit.  
  33.  
  34. #include <signal.h>
  35. signal(SIGINT,function)
  36.  
  37. In function() ( prototyped as void function(void) ) the first call should
  38. be signal(SIGINT,function) because the behavior of SIGINT is reset to default
  39. by the signal-handler.
  40.  
  41. Walter
  42.