home *** CD-ROM | disk | FTP | other *** search
- /*
- kbhit.c
- kbhit() returns 1 if a keypress awaits processing, 0 otherwise.
- getcharUnbuffered() always returns immediately. It returns value -1 if there's
- no character to return.
-
- getcharUnbuffered() is used by Choose.c
-
- 6/13/90 dgp wrote kbhit, based on suggestion from Michael Kahl and an earlier version by
- Evan Relkin.
- 12/25/93 dgp cosmetic editing
- 8/1/94 dgp added support for MetroWerks CodeWarrior C 3.5.
- 10/1/94 dgp updated for MetroWerks CodeWarrior C 4.5, which still doesn't support
- unbuffered input from the console.
- 10/8/94 dgp Discovered that GetNextEvent() works fine for unbuffered input in CodeWarrior C.
- */
- #include "VideoToolbox.h"
- #if (THINK_C || THINK_CPLUS)
- #include <console.h>
- #endif
- #if __MWERKS__
- #include <console.h>
- #endif
-
- int kbhit(void)
- {
- #if (THINK_C || THINK_CPLUS)
- int c;
-
- c=getcharUnbuffered();
- if(c==EOF)return 0;
- ungetc(c,stdin);
- return 1;
- #else
- EventRecord event;
-
- return EventAvail(keyDownMask,&event);
- #endif
- }
-
- int getcharUnbuffered(void)
- {
- #if (THINK_C || THINK_CPLUS)
- int c;
-
- csetmode(C_RAW,stdin); /* unbuffered: no echo, no editing */
- c=getchar();
- csetmode(C_ECHO,stdin); /* default mode: line-buffered, echo, full editing */
- #else
- int c;
- EventRecord event;
- #if __MWERKS__
- extern long __SIOUXtextWindow;
-
- SelectWindow((WindowPtr)__SIOUXtextWindow);
- #endif
- while(!GetNextEvent(keyDownMask,&event)) ;
- if((event.message&charCodeMask)=='.' && (event.modifiers&cmdKey)) abort();
- c=event.message&charCodeMask;
- #endif
- return c;
- }
-
-