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.
- 1/7/95 dgp Updated to take advantage of the CW5 SIOUX console's new ability to handle an event.
- */
- #include "VideoToolbox.h"
- #if (THINK_C || THINK_CPLUS)
- #include <console.h>
- #endif
- #if __MWERKS__
- #include <console.h>
- #include <SIOUX.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)
- {
- int c;
- #if (THINK_C || THINK_CPLUS)
-
- csetmode(C_RAW,stdin); /* unbuffered: no echo, no editing */
- c=getchar();
- csetmode(C_ECHO,stdin); /* default mode: line-buffered, echo, full editing */
- #else
- EventRecord event;
-
- while(!GetNextEvent(keyDownMask,&event)){
- #if __MWERKS__
- // Allow the console to respond to the mouse, e.g. drag, zoom, or resize.
- if(GetNextEvent(mDownMask|mUpMask,&event))SIOUXHandleOneEvent(&event);
- #endif
- }
- c=event.message&charCodeMask;
- if(c=='.' && (event.modifiers&cmdKey))abort();
- #endif
- return c;
- }
-
-