home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
volume_3.zip
/
KEYBOARD.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-28
|
4KB
|
206 lines
// I N C L U D E S ///////////////////////////////////////////////////////////
#include <dos.h>
#include <bios.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <ctype.h>
#include <iostream.h>
// F U N C T I O N S /////////////////////////////////////////////////////////
/*******************************************************
Function: unsigned char Get_Key(void)
Description:
*******************************************************/
unsigned char Get_Key(int *ch)
{
int Scan_Keys;
unsigned char Character;
// if there is a key waiting then return it, else return NULL
if (bioskey(1))
{
Scan_Keys = bioskey(0);
Character = Scan_Keys;
if( (Character >= 32) AND ( Character <= 127) ) //Normal Ascii test
{
*ch = FALSE; //Scan keys FALSE
return Character;//returns character
}
else
{
if(Character == 27) //Test for ESC, have it set for 27
{
*ch = ESC;
}
else
{
*ch = Scan_Keys; //Otherwise ch = #define stuff
} //like UP, BACKSPACE, ENTER etc
return(0);//No Ascii character returns Null
}
}
else
{
*ch = FALSE; //No Scan keys ch FALSE
return(0); //No Ascii char returns NULL
}
} // end Get_Ascii_Key
/*******************************************************
Function: unsigned int Get_Control_Keys(unsigned int mask)
Description:
*******************************************************/
unsigned int Get_Control_Keys(unsigned int mask)
{
// return the status of all the requested control key
return(mask & _bios_keybrd(_KEYBRD_SHIFTSTATUS));
} // end Get_Control_Keys
/*******************************************************
Function: void flush_buffer(void)
Description:
*******************************************************/
void flush_buffer(void)
{
while(kbhit())
{
getch();
}
return;
}
/*******************************************************
Function: void Pause(int tf)
Description:
*******************************************************/
void Pause(int tf)
{
if(tf == TRUE)
{
printf("\nPause Press a Key\n");
}
while(!kbhit()); //Waits for Key Press
flush_buffer(); //Clears buffer of any Key Pressed including arrow keys
return;
}
/*******************************************************
Function: int Key_Press(char *char_ch, int *Scan1, int *Alt_Ctrl)
Description:
*******************************************************/
int Key_Press(char *char_ch, int *Scan1, int *Alt_Ctrl)
{
union REGS KeyInRegister,KeyOutRegister;
struct SREGS segregs2;
*Alt_Ctrl = key();
*Scan1 = FALSE;
int Key_Pressed = bioskey(1); //Read Status
if(Key_Pressed != 0)
{
Key_Pressed = bioskey(0); //Read Character
*Scan1 = Key_Pressed;
*char_ch = ascii(Key_Pressed);
return (Key_Pressed & 0xFF);
}
return FALSE;
}
/*******************************************************
Function: int Check_ABC(int int_ch)
Description:
*******************************************************/
int Check_ABC(int int_ch)
{
if (isalpha(int_ch))
{
return TRUE;
}
return FALSE;
}
/*******************************************************
Function: char ascii(int int_ch)
Description:
*******************************************************/
char ascii(int int_ch)
{
char asc_char;
if (isascii(int_ch & 0xFF))
{
asc_char = (char)int_ch;
return (asc_char);
}
return NULL;
}
/*******************************************************
Function: int C_Break(void)
Description:
*******************************************************/
int C_Break(void)
{
union REGS regs;
regs.h.ah = 0x00;
regs.h.al = 3;
int86(0x10, ®s, ®s);
printf("Ctrl Break Pressed.....Program aborted");
return(0); //FALSE ENDS The Program
}
/*******************************************************
Function: int key()
Description:
*******************************************************/
int key()
{
union REGS KeyInRegister,KeyOutRegister;
struct SREGS segregs2;
KeyInRegister.x.ax = 0x0200; //Reads Flags
if(getvect(KEYBOARD_INTERRUPT)) //Checks for error
{
int86(KEYBOARD_INTERRUPT,&KeyInRegister,&KeyOutRegister);
if (KeyOutRegister.x.ax & RIGHT_SHIFT) return RIGHT_SHIFT;
if (KeyOutRegister.x.ax & LEFT_SHIFT) return LEFT_SHIFT;
if (KeyOutRegister.x.ax & CTRL) return CTRL;
if (KeyOutRegister.x.ax & ALT) return ALT;
return KeyOutRegister.x.ax;
}
return FALSE;
}