qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
CRTKEY.PAS
  Example Contents Index                                    Back
 
PROGRAM crtkey;
 
{ CRTKEY.PAS illustrates how to process ASCII or extended keys.
  Functions illustrated include:
 
      Ord    ReadKey    UpCase
 
  This program also uses the CheckBreak variable to disable CTRL/BREAK.
}
 
USES
    Crt;
 
CONST
    program_name = 'CRTKEY ';
    program_desc = 'uses the Crt unit to read and echo keystrokes.';
 
VAR
    key : Char;
 
BEGIN
 
    Writeln( program_name, program_desc );
    Writeln;
    CheckBreak := False;
    Writeln( 'Press any key (ESC to quit): ' );
 
    { Read and display keys until ESC is pressed. }
    WHILE True DO
        BEGIN
 
        { If first key is 0, then get second extended. }
        key := ReadKey;
        IF (key = #0) THEN
            BEGIN
            key := ReadKey;
            Write( 'ASCII: no     Char: NA   ');
            END {IF first key is 0}
 
        { Otherwise there's only one key. }
        ELSE
            BEGIN
            Write( 'ASCII: yes     ' );
            CASE Ord( key ) OF
                8  : Write( 'Char: BKSP ' );
                9  : Write( 'Char: TAB ' );
                13 : Write( 'Char: ENTER ' );
                ELSE Write( 'Char: ', key );
                END; { case }
            END; { ELSE processing one key }
        Writeln( '     Decimal: ', Ord( key ) );
 
        { Echo character response to prompt. }
        IF key = #27 THEN
            BEGIN
            Write( 'Do you really want to quit? (Y/N) ' );
            key := ReadKey;
            Writeln( key );
            IF (UpCase( key ) = 'Y') THEN Exit;
            END; { IF user types ESC }
        END; { WHILE true }
 
END.