home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
kbhit.c
< prev
next >
Wrap
Text File
|
1995-08-13
|
2KB
|
60 lines
/*
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.
6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
*/
#include "VideoToolbox.h"
int kbhit(void)
{
#if THINK_C
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
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))exit(1);
#endif
return c;
}