home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!kum.kaist.ac.kr!usenet
- From: typhoon@stcon2.kaist.ac.kr (Han Yun-Su)
- Subject: Re: Unix equivalent to DOS kbhit() function?
- Message-ID: <1992Dec29.073337.2693@kum.kaist.ac.kr>
- Sender: usenet@kum.kaist.ac.kr (news)
- Organization: KAIST in Seoul, Korea
- X-Newsreader: Tin 1.1 PL3
- Date: Tue, 29 Dec 92 07:33:37 GMT
- Lines: 67
-
- I wrote 'kbhit()' function for UNIX.
- It's very simple..
-
- Here's example source.
-
- Save this article as 'kbhit.c', delete headers and signature..
- Compile with -lcurses -ltermcap options, that is,
-
- cc kbhit.c -o kbhit -lcurses -ltermcap
-
- and..type kbhit !
- test some characters..
- (This works totaly fine for my SUN)
-
- Er..sorry.. I'm not good at english..:)
- I can speak C more fluently than english..hehe :)
- But my major is NOT Computer Science but Life Science.
-
- If you find better idea than this one, Please let me know.
-
- Good Luck!
-
-
- /* ---- Cut Here ---- */
- #include <sgtty.h>
- #include <curses.h>
-
- kbhit()
- {
- static unsigned i;
-
- ioctl(0, FIONREAD, &i);
- return i;
- }
-
- main()
- {
- unsigned long count = 0L;
- int c = ' ';
- int i = 0;
-
- initscr(); /* initialize curses functions */
- crmode(); /* cbreak mode */
- noecho(); /* do not echo pressed character */
-
- mvprintw(0, 0, "Press \'q\' to quit\n");
- refresh();
-
- while (c != 'q') {
- count++;
- if (kbhit()) {
- c = getch();
- mvprintw(1, 0, "%d: \'%c\' is pressed (count: %ld)\n", ++i, c, count);
- refresh();
- }
- }
-
- nocrmode();
- echo();
- endwin(); /* close curses... */
- }
- /* ---- Cut Here ---- */
-
- --
- Han Yun-Su, KAIST, Life Science | Life is short, DNA is long.
- Molecular Genetics Laboratory | DNAs, recombine in the neuclus!
- Tel: (042)-4061, 4786 | Slow and steady evolves the life.
-