home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / jove414s.zip / os2getch.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  3KB  |  138 lines

  1. /* keyboard functions for JOVE under OS/2 */
  2. #define INCL_BASE
  3. #include <os2.h>
  4. #include <conio.h>
  5. #define UNIFIED
  6.  
  7. extern int UpdModLine;
  8. static unsigned char last_char;
  9. KBDKEYINFO KeyInfo;
  10.  
  11. /***********************************************/
  12. unsigned int _fastcall getrawinchar (void)
  13. /***********************************************/
  14. {
  15.     long wait_time = 2000L;    /* total wait time */
  16.     long interval = 100L;    /* inerval between kbd poll */
  17.     unsigned char new_char;
  18.     unsigned char ret_char;
  19.     int kbdp = 0;
  20.     static unsigned char minutes = 0;
  21.     DATETIME DateTime;
  22.  
  23. /* return last character */
  24.     if (last_char != 0) {
  25.     new_char = last_char;
  26.     last_char = 0;
  27.     return (new_char);
  28.     }
  29.     DosGetDateTime(&DateTime);
  30.     while (kbhit() == 0) {
  31.     DosSleep(interval);
  32.     if (UpdModLine == 0) {
  33.         DosGetDateTime(&DateTime);
  34.         if (DateTime.minutes != minutes) {
  35.         UpdModLine = 1;
  36.         minutes = DateTime.minutes;
  37.         }
  38.     }
  39.     }
  40.     KbdCharIn(&KeyInfo, IO_WAIT, 0);
  41. //    if (KeyInfo.chChar <= 0xA8)
  42.     if (KeyInfo.chChar <= 0xFF && KeyInfo.chChar != 0xE0)
  43.     return (KeyInfo.chChar);
  44.     else {
  45.     last_char = KeyInfo.chScan;
  46.     return (0x00ff);
  47.     }
  48. }
  49.  
  50. /*********************************/
  51. int _fastcall rawkey_ready (void)
  52. /*********************************/
  53. {
  54.     if (last_char != 0)
  55.     return (1);
  56.     else
  57.     return (kbhit());
  58. }
  59.  
  60. /**************************/
  61. void os2_kbd_open(void)
  62. /**************************/
  63. /* initialize keyboard */
  64. {
  65.     KBDINFO kbdInfo;
  66.  
  67.     kbdInfo.cb = 0x000A;
  68.     KbdGetStatus(&kbdInfo, 0);
  69.     kbdInfo.fsMask &= ~0x0001;    /* not echo on        */
  70.     kbdInfo.fsMask |= 0x0002;    /* echo off        */
  71.     kbdInfo.fsMask &= ~0x0008;    /* cooked mode off    */
  72.     kbdInfo.fsMask |= 0x0004;    /* raw mode        */
  73.     kbdInfo.fsMask &= ~0x0100;    /* shift report    off    */
  74.     KbdSetStatus(&kbdInfo, 0);
  75. }
  76.  
  77.  
  78.  
  79. #ifdef UNIFIED
  80. /* function kbd_char unifies the functionality of GETRAWINCHAR, */
  81. /* and RAWKEY_READY */
  82.  
  83. typedef enum {
  84.     if_pressed_key,
  85.     get_character
  86. } KBD_REQUEST;
  87.  
  88. /**************************************************************/
  89. int _fastcall kbd_char(KBD_REQUEST request, int *UpdModLine)
  90. /**************************************************************/
  91. {
  92.  
  93.     long wait_time = 2000L;    /* total wait time */
  94.     long interval = 100L;    /* inerval between kbd poll */
  95.     unsigned char new_char;
  96.     unsigned char ret_char;
  97.     int kbdp = 0;
  98.     static unsigned char minutes = 0;
  99.     DATETIME DateTime;
  100.  
  101.     switch (request) {
  102.     case (if_pressed_key):
  103.     if (last_char != 0)
  104.         return (1);
  105.     else
  106.         return (kbhit());
  107.     break;
  108.     case (get_character):
  109.     if (last_char != 0) {
  110.         new_char = last_char;
  111.         last_char = 0;
  112.         return (new_char);
  113.     }
  114.     DosGetDateTime(&DateTime);
  115.     while (kbhit() == 0) {
  116.         DosSleep(interval);
  117.         if (*UpdModLine == 0) {
  118.         DosGetDateTime(&DateTime);
  119.         if (DateTime.minutes != minutes) {
  120.             *UpdModLine = 1;
  121.             minutes = DateTime.minutes;
  122.         }
  123.         }
  124.     }
  125.     KbdCharIn(&KeyInfo, IO_WAIT, 0);
  126.     if (KeyInfo.chChar <= 0xA8)
  127.         return (KeyInfo.chChar);
  128.  
  129.     else {
  130.         last_char = KeyInfo.chScan;
  131.         return (0x00ff);
  132.     }
  133.     }
  134.  
  135. }
  136.  
  137. #endif
  138.