home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / s12628.zip / KBD.C < prev    next >
Text File  |  1990-07-01  |  2KB  |  63 lines

  1. /* kbd.c
  2.  *
  3.  * keyboard thread code for PMAccess
  4.  */
  5.  
  6. #define INCL_SUB
  7. #define INCL_DOS
  8. #include<os2.h>
  9. #include"kbd.h"
  10. #include"kbddefs.h"
  11. #include"msgq.h"
  12. #include"button.h"
  13. #include"msgs.h"
  14.  
  15. extern long KbdSem;
  16. extern PCHAR mainmsgqueue;
  17. extern BUTTON buttonlist[];
  18.  
  19. USHORT AcceleratorPressed(unsigned char key);
  20.  
  21. void KbdThread(void)
  22.     {
  23.     KBDINFO     kbdinfo;
  24.     KBDKEYINFO  KbdKeyInfo;
  25.     HKBD        KbdHandle = 0;
  26.     HQUEUE      qhandle;
  27.     USHORT      event;
  28.  
  29.     MsgQOpen(&qhandle,mainmsgqueue);
  30.  
  31.     KbdFlushBuffer(KbdHandle);          // flush keyboard buffer
  32.     KbdGetStatus(&kbdinfo,KbdHandle);   // get keyboard status
  33.     kbdinfo.fsMask &= ~COOKED;          // turn off COOKED bit
  34.     kbdinfo.fsMask |= RAW;              // turn on RAW bit
  35.     KbdSetStatus(&kbdinfo,KbdHandle);   // set the keyboard status
  36.     DosSemClear(&KbdSem);               // notify main thread
  37.  
  38.     while(TRUE)
  39.         {
  40.         KbdCharIn(&KbdKeyInfo,IO_WAIT,KbdHandle);// get a character
  41.         if(KbdKeyInfo.chChar)                    // if Ascii code
  42.           MsgQSend(qhandle,&KbdKeyInfo,sizeof(KbdKeyInfo),MSG_CHAR);
  43.         else if(event = AcceleratorPressed(KbdKeyInfo.chScan))
  44.           MsgQSend(qhandle,NULL,0,event); //if Accelerator,pass it on
  45.         else
  46.             MsgQSend(qhandle,&KbdKeyInfo,sizeof(KbdKeyInfo),
  47.                 SCANCODE(KbdKeyInfo.chScan));
  48.         DosSleep(32L);
  49.         }
  50.     }
  51.  
  52. USHORT AcceleratorPressed(unsigned char key)
  53.     {
  54.     BUTTON *b = &buttonlist[0];
  55.  
  56.     for( ; b->text; b++)
  57.         if(key == (unsigned char)b->accelerator)
  58.             return MOUSECODE(b->left_button_val);
  59.     return 0;
  60.     }
  61.  
  62.     /********** end of keyboard thread code *******************/
  63.