home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / volume_3.zip / KEYBOARD.CPP < prev    next >
C/C++ Source or Header  |  1995-10-28  |  4KB  |  206 lines

  1. // I N C L U D E S ///////////////////////////////////////////////////////////
  2.  
  3. #include <dos.h>
  4. #include <bios.h>
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <conio.h>
  8. #include <ctype.h>
  9. #include <iostream.h>
  10.  
  11.  
  12. // F U N C T I O N S /////////////////////////////////////////////////////////
  13.  
  14. /*******************************************************
  15. Function: unsigned char Get_Key(void)
  16.  
  17. Description:
  18. *******************************************************/
  19. unsigned char Get_Key(int *ch)
  20. {
  21. int Scan_Keys;
  22. unsigned char Character;
  23. // if there is a key waiting then return it, else return NULL
  24. if (bioskey(1))
  25.     {
  26.      Scan_Keys = bioskey(0);
  27.      Character = Scan_Keys;
  28.      if( (Character >=  32) AND ( Character <=  127) ) //Normal Ascii test
  29.         {
  30.         *ch = FALSE;  //Scan keys FALSE
  31.         return Character;//returns character
  32.         }
  33.      else
  34.         {
  35.         if(Character == 27) //Test for ESC, have it set for 27
  36.             {
  37.             *ch = ESC;
  38.             }
  39.         else
  40.             {
  41.             *ch = Scan_Keys; //Otherwise ch = #define stuff
  42.             }                //like UP, BACKSPACE, ENTER etc
  43.         return(0);//No Ascii character returns Null
  44.         }
  45.     }
  46. else
  47.     {
  48.     *ch = FALSE; //No Scan keys ch FALSE
  49.     return(0); //No Ascii char returns NULL
  50.     }
  51. } // end Get_Ascii_Key
  52.  
  53.  
  54.  
  55. /*******************************************************
  56. Function: unsigned int Get_Control_Keys(unsigned int mask)
  57.  
  58. Description:
  59. *******************************************************/
  60. unsigned int Get_Control_Keys(unsigned int mask)
  61. {
  62. // return the status of all the requested control key
  63. return(mask & _bios_keybrd(_KEYBRD_SHIFTSTATUS));
  64. } // end Get_Control_Keys
  65.  
  66.  
  67. /*******************************************************
  68. Function: void flush_buffer(void)
  69.  
  70. Description:
  71. *******************************************************/
  72. void flush_buffer(void)
  73. {
  74. while(kbhit())
  75.     {
  76.     getch();
  77.     }
  78. return;
  79. }
  80.  
  81.  
  82.  
  83.  
  84. /*******************************************************
  85. Function: void Pause(int tf)
  86.  
  87. Description:
  88. *******************************************************/
  89. void Pause(int tf)
  90. {
  91. if(tf == TRUE)
  92.     {
  93.     printf("\nPause Press a Key\n");
  94.     }
  95. while(!kbhit()); //Waits for Key Press
  96. flush_buffer(); //Clears buffer of any Key Pressed including arrow keys
  97. return;
  98. }
  99.  
  100.  
  101.  
  102.  
  103. /*******************************************************
  104. Function: int Key_Press(char *char_ch, int *Scan1, int *Alt_Ctrl)
  105.  
  106. Description:
  107. *******************************************************/
  108. int Key_Press(char *char_ch, int *Scan1, int *Alt_Ctrl)
  109. {
  110. union REGS KeyInRegister,KeyOutRegister;
  111. struct SREGS segregs2;
  112. *Alt_Ctrl = key();
  113. *Scan1 = FALSE;
  114. int Key_Pressed = bioskey(1); //Read Status
  115. if(Key_Pressed != 0)
  116.     {
  117.     Key_Pressed = bioskey(0);  //Read Character
  118.     *Scan1 = Key_Pressed;
  119.     *char_ch = ascii(Key_Pressed);
  120.     return (Key_Pressed & 0xFF);
  121.     }
  122. return FALSE;
  123. }
  124.  
  125.  
  126.  
  127. /*******************************************************
  128. Function: int Check_ABC(int int_ch)
  129.  
  130. Description:
  131. *******************************************************/
  132. int Check_ABC(int int_ch)
  133. {
  134. if (isalpha(int_ch))
  135.     {
  136.     return TRUE;
  137.     }
  138. return FALSE;
  139. }
  140.  
  141.  
  142.  
  143.  
  144. /*******************************************************
  145. Function: char ascii(int int_ch)
  146.  
  147. Description:
  148. *******************************************************/
  149. char ascii(int int_ch)
  150. {
  151. char asc_char;
  152. if (isascii(int_ch & 0xFF))
  153.     {
  154.     asc_char = (char)int_ch;
  155.     return (asc_char);
  156.     }
  157. return NULL;
  158. }
  159.  
  160.  
  161. /*******************************************************
  162. Function: int C_Break(void)
  163.  
  164. Description:
  165. *******************************************************/
  166. int C_Break(void)
  167. {
  168. union REGS regs;
  169. regs.h.ah = 0x00;
  170. regs.h.al = 3;
  171. int86(0x10, ®s, ®s);
  172. printf("Ctrl Break Pressed.....Program aborted");
  173. return(0); //FALSE ENDS The Program
  174. }
  175.  
  176.  
  177.  
  178. /*******************************************************
  179. Function: int key()
  180.  
  181. Description:
  182. *******************************************************/
  183. int key()
  184. {
  185. union REGS KeyInRegister,KeyOutRegister;
  186. struct SREGS segregs2;
  187. KeyInRegister.x.ax =  0x0200;   //Reads Flags
  188. if(getvect(KEYBOARD_INTERRUPT)) //Checks for error
  189.  {
  190.     int86(KEYBOARD_INTERRUPT,&KeyInRegister,&KeyOutRegister);
  191.     if (KeyOutRegister.x.ax & RIGHT_SHIFT) return  RIGHT_SHIFT;
  192.     if (KeyOutRegister.x.ax & LEFT_SHIFT)  return  LEFT_SHIFT;
  193.     if (KeyOutRegister.x.ax & CTRL)  return  CTRL;
  194.     if (KeyOutRegister.x.ax & ALT)   return  ALT;
  195.  
  196.     return KeyOutRegister.x.ax;
  197.  }
  198. return FALSE;
  199. }
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.