home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / test / kbd.cpp < prev    next >
C/C++ Source or Header  |  1999-05-25  |  1KB  |  69 lines

  1. #define INCL_SUB
  2. #define INCL_DOSPROCESS
  3. #include <os2.h>
  4. #include <stdio.h>
  5.  
  6. void main()
  7. {
  8. HKBD KbdHandle;
  9. KBDKEYINFO pkbci;
  10. USHORT rc;
  11. KBDINFO StatData;
  12.  
  13. rc = KbdOpen( &KbdHandle );
  14. if( rc ){
  15.     printf("KbdOpen error\n");
  16.     return;
  17.     }
  18. rc = KbdGetFocus( 0, KbdHandle );
  19. if( rc ){
  20.     printf("KbdGetFocus error, rc = %d\n", rc);
  21.     return;
  22.     }
  23.  
  24. StatData.cb = sizeof( StatData );
  25. StatData.fsMask = 0x4;
  26. StatData.chTurnAround = 0;
  27. StatData.fsInterim = 0;
  28. StatData.fsState = 0;
  29.  
  30. rc = KbdSetStatus( &StatData, KbdHandle );
  31. if( rc ){
  32.     printf("KbdSetStatus error, rc = %d\n", rc);
  33.     return;
  34.     }
  35.  
  36. while(1)
  37.     {
  38.     rc = KbdCharIn( &pkbci, 1, KbdHandle );
  39.     if( rc ){
  40.         printf("KbdCharIn error, rc = %d\n", rc);
  41.         break;
  42.         }
  43.     int kbReady = 0;
  44.     int shiftstate;    // 0-bit: Shift
  45.     shiftstate = 0;    // 1-bit: Ctrl
  46.                             // 2-bit: Alt
  47.     shiftstate |= ( (pkbci.fsState & 3) > 0 ) ? 1 : 0;    // Shift state
  48.     shiftstate |= ( (pkbci.fsState & 4) > 0 ) ? 2 : 0;    // Ctrl state
  49.     shiftstate |= ( (pkbci.fsState & 8) > 0 ) ? 4 : 0;    // Alt state
  50.     kbReady |= ( (pkbci.fbStatus & 64) > 0 ) ? 1 : 0;
  51.     if( kbReady )
  52.     printf(" { %d,\t%d,\t%d,\t%d },\n",
  53.         pkbci.chChar,
  54.         pkbci.chScan, 
  55.         shiftstate,
  56.         pkbci.fbStatus
  57.         );
  58.     DosSleep( 10 );
  59.     }
  60. rc = KbdFreeFocus( KbdHandle );
  61. if( rc ){
  62.     printf("KbdFreeFocus error, rc = %d\n", rc);
  63.     return;
  64.     }
  65.  
  66. KbdClose( KbdHandle );
  67.  
  68. }
  69.