home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
flash-c1.zip
/
CH3_1.DOC
< prev
next >
Wrap
Text File
|
1990-02-11
|
12KB
|
484 lines
..pgno01
..foot63A3-##
..head02L──────────────────────────────────────────────────────────────────────
..head04L──────────────────────────────────────────────────────────────────────
..head03ABiosKbdClr
■ Description
Clear the keyboard buffer.
■ Summary
Procedure BiosKbdClr;
■ Remarks
BiosKbdClr uses the BIOS to clear any characters in the keyboard
buffer waiting to be read.
■ See Also
DosKbdClr
■ Example
#include <fpclib.h>
main()
{
int Ch;
BiosKbdClr();
Ch = GetKey();
}
In this example the keyboard buffer is flushed before reading a
keystroke from the keyboard.
..page
..head03ABiosKbdGetElmt
■ Description
Returns an integer value for the key pressed on the keyboard.
■ Summary
Function BiosKbdGetElmt : Integer;
■ Remarks
BiosKbdGetElmt will return an integer in the range of 0-388. Use
Appendix C as a guide to find the keyboard element code this
function returns for a particular key pressed on the keyboard.
When using DOS function calls there is not any method available to
distinguish the difference between some keystokes and key
combinations. An example of this is the Enter key and the Ctrl-M
keys, both return a value of 145. Key combinations using the control
key with an alpha character and all other ascii characters will be
offset by 132.
■ See Also
BiosKbdRead, DosKbdGetElmt, DosKbdRead
■ Example
#include <fpclib.h>
main()
{
printf( "Value of keypressed = %u \n", BiosKbdGetElmt() );
}
If Control-Break were pressed then zero would be displayed. If the
'A' were pressed then 197 would be displayed: (197 - 132 = 65).
..page
..head03ABiosKbdHit
■ Description
Reports if a keystroke is waiting to be read from the keyboard
buffer.
■ Summary
Function BiosKbdHit : Boolean;
■ Remarks
Using the BIOS services BiosKbdHit checks the keyboard status to
determine if a key is waiting to be read from the keyboard buffer.
■ See Also
DosKbdHit
■ Example
#include <fpclib.h>
main()
{
while ( !BiosKbdHit() )
printf( "Keyboard buffer empty...\n" );
}
This program will display the keyboard buffer empty phrase on a new
line until a key is pressed on the keyboard.
..page
..head03ABiosKbdRead
■ Description
Read a character from the keyboard.
■ Summary
Procedure BiosKbdRead( Var Ch : String );
Ch returns a string of length zero, one, or two bytes long
defining the key or key combination pressed from the
keyboard.
■ Remarks
BiosKbdRead reads a single character from the keyboard buffer.
BiosKbdRead will return a zero, one, or two character string. A
null string indicates that Ctrl- Break was pressed. A one-character
string indicates a normal ascii character was read from the
keyboard. A two-character string indicates a special extended
keyboard code. Refer to appendix B for a list of the extended
keyboard codes. The data type definition for BiosKbdRead is an
untyped variable using a minimum of three bytes.
■ See Also
BiosKbdGetElmt, DosKbdGetElmt, DosKbdRead
..page
■ Example
#include <fpclib.h>
main()
{
char Ch[2];
BiosKbdRead( Ch );
switch ( Ch[0] )
case 0 : printf( "Ctrl char pressed" ); break;
case 27 : printf( "Other key comb used" ); break;
default : if ( Ch[0] > 31 && Ch[0] < 128 )
printf( "ASCII pressed" );
}
}
In this example any key or key combination that is read from the
keyboard will be grouped into one of three categories.
If Ch[1] is equal to the null byte and the length byte is equal to
two, then one of the control characters (0-31) was pressed. This
includes the enter key, backspace, tab, and key combinations that
use the control and an ACSII character A-Z. If Ch[1] is equal to
#27 then some other key combination was used, generally involving
the alt key or control key with one of the function keys or cursor
movement keys. The string length will be two. If Ch[1] is in the
range #32..#127 then an ASCII character was pressed. The length
will also be one, where as in the other two possibilites the length
will be two.
..page
..head03ABiosKbdStat
■ Description
Get the keyboard status byte
■ Summary
Function BiosKbdStat : Intger;
■ Remarks
BiosKbdStat returns the keyboard status byte as follows:
BITS
─────────────────────────────────
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
─────────────────────────────────
Bit Bit Value Key Pressed
--- --------- ──────────-
0 1 Right Shift
1 2 Left Shift
2 4 Control
3 8 Alternate
Key Mode
───────────
4 16 Scroll Lock
5 32 Num Lock
6 64 Caps Lock
7 128 Insert
A one in the bit position means the condition is true and a zero in
the bit position means the condition is false.
..page
■ Example
#include <fpclib.h>
main()
{
int i,done = 0;
VioInit(); /* need for ClrWin */
while ( !done ) {
i = BiosKbdStat();
if ( BiosKbdHit() ) {
if ( i & 2 )
done++;
ClrWin( 1, 1, 80, 25, 7 );
if ( i & 16 ) printf( "Scroll Lock ON \n" );
else printf( "Scroll Lock OFF\n" );
if ( i & 32 ) printf( "Num Lock ON \n" );
else printf( "Num Lock OFF\n" );
if ( i & 64 ) printf( "Caps Lock ON \n" );
else printf( "Caps Lock OFF\n" );
if ( i & 128 ) printf( "Insert ON \n" );
else printf( "Insert OFF\n" );
}
}
}
In this example everytime a key is pressed the screen is cleared and
the status for the Scroll Lock, Insert, Caps Lock and Num Lock keys
is displayed in the upper left corner. This routine will not
terminate until a key is pressed with the left shift key held down.
..page
..head03ADosKbdClr
■ Description
Clear the keyboard buffer.
■ Summary
Procedure DosKbdClr;
■ Remarks
DosKbdClr uses DOS to clear any characters in the keyboard buffer
waiting to be read.
■ See Also
BiosKbdClr
■ Example
#include <fpclib.h>
main()
{
int Ch;
DosKbdClr();
Ch = GetKey();
}
In this example the keyboard buffer is flushed before reading a
keystroke from the keyboard.
..page
..head03ADosKbdGetElmt
■ Description
Returns an integer value for the key pressed on the keyboard.
■ Summary
Function DosKbdGetElmt : Integer;
■ Remarks
DosKbdGetElmt will return an integer in the range of 0-388. Use
Appendix C to find the keyboard element code this function returns
for a particular key pressed on the keyboard.
Key combinations using the control key with an alpha character and
all other ascii characters will be offset by 132.
■ See Also
BiosKbdGetElmt, BiosKbdRead, DosKbdRead
■ Example
#include <fpclib.h>
main()
{
printf( "Value of keypressed = %u\n", DosKbdGetElmt() );
}
If Control-Break were pressed then zero would be displayed. If the
'A' were pressed then 197 would be displayed: (197 - 132 = 65).
..page
..head03ADosKbdHit
■ Description
Reports if a keystroke is waiting to be read from the keyboard
buffer.
■ Summary
Function DosKbdHit : Boolean;
■ Remarks
Using the DOS services DosKbdHit checks the keyboard status to
determine if a key is waiting to be read from the keyboard buffer.
■ See Also
BiosKbdHit
■ Example
#include <fpclib.h>
main()
{
while ( !DosKbdHit() )
printf( "Keyboard buffer empty...\n" );
}
This program will display the keyboard buffer empty phrase on a new
line until a key is pressed on the keyboard.
..page
..head03ADosKbdRead
■ Description
Read a character from the keyboard.
■ Summary
Procedure DosKbdRead( Var Ch : String );
Ch returns a string of length zero, one, or two bytes long
defining the key or key combination pressed from the
keyboard.
■ Remarks
DosKbdRead reads a single character from the keyboard buffer.
DosKbdRead will return a zero, one, or two character string. A null
string indicates that Ctrl- Break was pressed. A one-character
string indicates a normal ascii character was read from the
keyboard. A two-character string indicates a special extended
keyboard code. Refer to appendix B for a list of the extended
keyboard codes. The data type definition for DosKbdRead is an
untyped variable using a minimum of three bytes.
■ See Also
BiosKbdGetElmt, BiosKbdRead, DosKbdGetElmt
..page
■ Example
#include <fpclib.h>
main()
{
char Ch[2];
DosKbdRead();
switch ( Ch[0] ) {
case 0 : printf( "Ctrl char pressed\n" ); break;
case 27 : printf( "Other key comb used\n" ); break;
default : if ( Ch[0] > 31 && Ch[0] < 128 )
printf( "ASCII pressed\n" );
}
}
In this example any key or key combination that is read from the
keyboard will be grouped into one of three categories.
If Ch[1] is equal to the null byte and the length byte is equal to
two, then one of the control characters (0-31) was pressed. This
includes the enter key, backspace, tab, and key combinations that
use the control and an ACSII character A-Z. If Ch[1] is equal to
#27 then some other key combination was used, generally involving
the alt key or control key with one of the function keys or cursor
movement keys. The string length will be two. If Ch[1] is in the
range #32..#127 then an ASCII character was pressed. The length
will also be one, where as in the other two possibilites the length
will be two.
..page
..head03AGetKey
■ Description
Returns a keystroke and map it into a keyboard element number for
EditSt.
■ Summary
Function GetKey : Integer;
■ Remarks
This function may call other functions and procedures if it so
desires. The only restriction is that it must return an integer
value that is in the table found in Appendix C if the function
EditSt is used. If EditSt is not used the only restriction is that
an integer must be returned.
■ Example
#include <fpclib.h>
INT GetKey( void )
{
int i;
while ( !DosKbdHit() ) {
FillRowChar( 1, 25, 80, ' ' );
i = BiosKbdStat();
if ( i & 16 ) ColorMsg( 1, 25, 7, "Scroll" );
if ( i & 32 ) ColorMsg( 8, 25, 7, "Num" );
if ( i & 64 ) ColorMsg( 12, 25, 7, "Caps" );
if ( i & 128 ) ColorMsg( 17, 25, 7, "Insert" );
}
return( BiosKbdGetElmt() );
}
main()
{
printf( "Key element number = %u\n", GetKey() );
}
This example polls the keyboard, gets the keyboard status byte and
displays the status for four keys while a key has not been pressed.
Once a key has been pressed on the keyboard the BiosKbdGetElmt
function is called to get the keyboard element number.
..page