home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / courses / kbhit.c < prev    next >
C/C++ Source or Header  |  1992-07-09  |  699b  |  39 lines

  1. /*
  2.  * kbhit()
  3.  *
  4.  * Implimention of the above library call.
  5.  *
  6.  * Replaces the broken implimentation of kbhit() found in the Watcom C/386 9.0
  7.  * libraries.
  8.  *
  9.  * Copyright July 1992 by G. R. (Fred) Walter
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #define INCL_KBD
  15. #include <os2.h>
  16.  
  17. static KBDKEYINFO *_kbhit_keyinfo = NULL;
  18.  
  19. int
  20. kbhit()
  21. {
  22.     if (_kbhit_keyinfo == NULL) {
  23.         _kbhit_keyinfo = (KBDKEYINFO *)malloc(sizeof(KBDKEYINFO));
  24.         if (_kbhit_keyinfo == NULL) {
  25.             fprintf(stderr, "Out of memory error\n");
  26.             exit(1);
  27.         }
  28.     }
  29.             
  30.     if (KbdPeek(_kbhit_keyinfo, 0) != 0)
  31.         return (0);
  32.  
  33.     if (_kbhit_keyinfo->fbStatus & 0x40)
  34.         return (1);
  35.     else
  36.         return (0);
  37. }
  38.  
  39.