home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / WATCOM.ZIP / WATCOM.TXT
Internet Message Format  |  1993-02-14  |  2KB

  1. From: fredw@mks.com (Fred Walter)
  2. Subject: Watcom C/386 9.0 getch() and kbhit() + PC-CURSES1.3-2 + sc 6.21
  3. Organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA
  4. Date: Fri, 10 Jul 1992 16:26:26 GMT
  5.  
  6. Watcom C/386 9.0's implimentation of getch() and kbhit() are broken.
  7. Watcom tech support knows this, and it will be fixed in the next release.
  8. If you don't want to wait until the next release to use these functions
  9. you could use the ones that I wrote (which I've tacked onto the end of this
  10. posting).
  11.  
  12.     fred
  13. ------------------------------------------------------------------------------
  14. /*
  15.  * getch()
  16.  *
  17.  * Implimention of the above library call.
  18.  *
  19.  * Replaces the broken implimentation of getch() found in the Watcom C/386 9.0
  20.  * libraries. Note: Watcom's ungetch() probably won't work with my new getch().
  21.  *
  22.  * Copyright July 1992 by G. R. (Fred) Walter
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #define INCL_KBD
  28. #include <os2.h>
  29.  
  30. static char        _getch_flag = 0; 
  31. static KBDKEYINFO *_getch_keyinfo = NULL;
  32.  
  33. int
  34. getch()
  35. {
  36.     if (_getch_keyinfo == NULL) {
  37.         _getch_keyinfo = (KBDKEYINFO *)malloc(sizeof(KBDKEYINFO));
  38.         if (_getch_keyinfo == NULL) {
  39.             fprintf(stderr, "Out of memory error\n");
  40.             exit(1);
  41.         }
  42.     }
  43.             
  44.     if (_getch_flag != 0) {
  45.         _getch_flag = 0;
  46.         return (_getch_keyinfo->chScan);
  47.     }
  48.  
  49.     if (KbdCharIn(_getch_keyinfo, IO_WAIT, 0) != 0)
  50.         return (EOF);
  51.  
  52.     if (_getch_keyinfo->chChar == 0x00 || _getch_keyinfo->chChar == 0xE0) {
  53.         _getch_keyinfo->chChar = 0;
  54.         _getch_flag = 1;
  55.     }
  56.  
  57.     return (_getch_keyinfo->chChar);
  58. }
  59. ------------------------------------------------------------------------------
  60. /*
  61.  * kbhit()
  62.  *
  63.  * Implimention of the above library call.
  64.  *
  65.  * Replaces the broken implimentation of kbhit() found in the Watcom C/386 9.0
  66.  * libraries.
  67.  *
  68.  * Copyright July 1992 by G. R. (Fred) Walter
  69.  */
  70.  
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #define INCL_KBD
  74. #include <os2.h>
  75.  
  76. static KBDKEYINFO *_kbhit_keyinfo = NULL;
  77.  
  78. int
  79. kbhit()
  80. {
  81.     if (_kbhit_keyinfo == NULL) {
  82.         _kbhit_keyinfo = (KBDKEYINFO *)malloc(sizeof(KBDKEYINFO));
  83.         if (_kbhit_keyinfo == NULL) {
  84.             fprintf(stderr, "Out of memory error\n");
  85.             exit(1);
  86.         }
  87.     }
  88.             
  89.     if (KbdPeek(_kbhit_keyinfo, 0) != 0)
  90.         return (0);
  91.  
  92.     if (_kbhit_keyinfo->fbStatus & 0x40)
  93.         return (1);
  94.     else
  95.         return (0);
  96. }
  97. -- 
  98. Disclaimer: everything I write is my *personal* opinion and does not represent
  99. or reflect the opinion of the company which employs me.
  100.