{***********************************************************************}
{									}
{ __ExRdyKey  Return a character and scan code if one is available in	}
{	      the keyboard buffer.					}
{									}
{ function  __ExRdyKey(UseExtended : boolean;				}
{			var ThisCh : char;				}
{		      var ScanCode : byte) : boolean;			}
{									}
{	      UseExtended						}
{			Use the extended BIOS function $11 if available }
{	      ThisCh	The next character in the keyboard buffer if	}
{			one is ready.  If the next entry is an extended }
{			character sequence, the NUL character (ASCII	}
{			code 0) or ASCII $E0 (if the Enhanced Keyboard	}
{			is present) is returned.			}
{	      ScanCode	The scan code of the returned character or ex-	}
{			tended character code.				}
{									}
{ Description If a key sequence is in the keyboard buffer, this function}
{	      returns a value of TRUE; otherwise FALSE.  In case a	}
{	      sequence is available, the character and scan code are	}
{	      returned.  The returned parameters are not assigned a	}
{	      value if the keyboard buffer is empty.  When UseExtended	}
{	      is set to TRUE, __ExRdyKey does a nondestructive read of	}
{	      the keyboard buffer; that is, the character sequence	}
{	      remains in the buffer.  If UseExtended is set to FALSE,	}
{	      __ExRdyKey uses the traditional BIOS call (function 1)	}
{	      which will clear the keyboard buffer of Enhanced Key-	}
{	      strokes (for example, F11 and F12), as well as  trans-	}
{	      late keys that are duplicated on the Enhanced Keyboard	}
{	      to their counterparts on the original keyboard.  (This	}
{	      incidentally, is how DOS versions through 3.30 handle the }
{	      keyboard.)  This means __ExRdyKey can return FALSE even	}
{	      though a key has been pressed, if an Enhanced Keyboard is }
{	      installed and UseExtended is set to FALSE.		}
{									}
{	      Call __ExRdyKey with UseExtended set to TRUE if you want	}
{	      to recognize the additional keys of the Enhanced Keyboard }
{	      or distinguish between duplicated keys like up-arrow and	}
{	      pad-up-arrow.						}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __ExRdyKey(UseExtended : boolean;
		      var ThisCh : char;
		    var ScanCode : byte) : boolean;

  var Reg : registers;

  begin {__ExRdyKey}

    with Reg do 		       { Prepare to call BIOS function	}
      begin			       { $16, subfunction $11.		}
	Flags := 0;
	if ((_ExtendedKbdBIOS) and (UseExtended)) then
	  AH := $11		       { Use extended BIOS call 	}
	else
	  AH := $01;
	Intr(_KEYBD,Reg);
	if ((Flags and FZero) = 0) then
	   begin		       { Keystroke is ready, so return	}
	     ScanCode	:= AH;	       { the values.			}
	     ThisCh	:= char(AL);
	     __ExRdyKey := TRUE
	   end
	else
	   __ExRdyKey := FALSE
      end

  end;	{__ExRdyKey}
