home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / event / keyboard.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-10  |  2.4 KB  |  104 lines

  1. #ifndef _KEYBOARD_HPP
  2. #define _KEYBOARD_HPP
  3.  
  4. //---------------------------------------------------------------------------
  5. // File:            KEYBOARD.HPP
  6. // Path:            ...\REHACK\EVENT\KEYBOARD.HPP
  7. // Version:        1.00
  8. // Author:        Bob Provencher
  9. // CIS Id:        71621,2632
  10. // Created On:        7/6/93
  11. // Modified On:
  12. // Description:    
  13. // Tabs:            5
  14. //---------------------------------------------------------------------------
  15.  
  16. #include <dos.h>
  17.  
  18. #ifndef _EVENT_HPP
  19. #include "..\event\eventq.hpp"
  20. #endif
  21.  
  22. const char     charUndef    = 0x00,    charBkSpc    = 0x08,    charTab    = 0x09,
  23.             charEnter    = 0x0D,    charUp    = 0x18,    charDown    = 0x19,
  24.             charRight    = 0x1A,    charLeft    = 0x1B;
  25.  
  26. const byte     scanESC    = 0x01,    scanF1    = 0x3B,    scanF2    = 0x3C,
  27.             scanF3    = 0x3D,    scanF4    = 0x3E,    scanF5    = 0x3F,
  28.             scanF6    = 0x40,    scanF7    = 0x41,    scanF8    = 0x42,
  29.             scanF9    = 0x43,    scanF10    = 0x44,    scanF11    = 0x57,
  30.             scanF12    = 0x58,    scanScrLk    = 0x46,    scanIns    = 0x52,
  31.             scanHome    = 0x47,    scanPgUp    = 0x49,    scanDel    = 0x53,
  32.             scanEnd    = 0x4F,    scanPgDn    = 0x51,    scanNum    = 0x45,
  33.             scanCaps    = 0x3A,    scanScrl    = 0x46,    scanCtrl    = 0x1D,
  34.             scanLCtrl = 0x1D,    scanRCtrl    = 0x10,    scanLShft = 0x2A,
  35.             scanRShft = 0x36,    scanAlt    = 0x38;
  36.  
  37. const byte    stateRShft = 0x01,    stateLShft = 0x02,
  38.             stateShift = 0x03,    stateCtrl    = 0x04,
  39.             stateAlt    = 0x08,    stateScrl    = 0x10,
  40.             stateNum    = 0x20,    stateCaps    = 0x40;
  41.  
  42. const byte    dataPort   = 0x60;
  43.  
  44. class Keyboard
  45. {
  46.  
  47. protected:
  48.  
  49.     static bool    installed, extended, keyDown;
  50.  
  51.     static bool    inKeyCaps, inKeyScroll, inKeyNum;
  52.  
  53.     static Event curEvent;
  54.  
  55.     static void    interrupt (*oldhandler)(...);
  56.  
  57.     static byte FAR* const pState;    // pointer to BIOS key state
  58.  
  59.     static const char    keyToChar[ 89 ][ 2 ];
  60.  
  61.     static void read( byte& );
  62.  
  63.     static void setState(   byte, bool = true );
  64.     static void resetState( byte b ) { setState( b, false ); }
  65.  
  66.     static bool testState(  byte b ) { return bool( *pState & b ); }
  67.  
  68.     static void toggleState( const byte );
  69.  
  70.     static bool test( byte );
  71.  
  72. public:
  73.  
  74.     static void install();
  75.     static void remove();
  76.  
  77.     static bool isInstalled()    { return installed; }
  78.  
  79.     static void interrupt handler(...);
  80.  
  81.     virtual ~Keyboard();
  82.  
  83. };
  84.  
  85. inline void Keyboard::setState( byte b, bool flag )
  86. {
  87.     if ( flag )
  88.         *pState |= b;
  89.     else
  90.         *pState &= ~b;
  91. }
  92.  
  93. inline void Keyboard::toggleState( const byte b )
  94. {
  95.     *pState ^= b;
  96. }
  97.  
  98. inline void Keyboard::read( byte& b )
  99. {
  100.     b = inport( dataPort );
  101. }
  102.  
  103. #endif    // _KEYBOARD_HPP
  104.