{***********************************************************************}
{									}
{ __StatKey   Return the keyboard status				}
{									}
{ function  __StatKey(var Status : _KeyStatus) : longint;		}
{									}
{	      Status	The keyboard shift status record returned	}
{									}
{ Description This function returns the keyboard shift status in the	}
{	      record of booleans describing each status.  The record	}
{	      structure is defined in the unit interface.  The function }
{	      value is a longint, the lower 18 bits of which describe	}
{	      which status is TRUE.  The possible bit settings are:	}
{									}
{	      Bit Position     Description				}
{	      ------------     --------------------------		}
{		*  17	       Right Ctrl shift depressed		}
{		*  16	       Right Alt shift depressed		}
{		   15	       Insert state is active			}
{		   14	       Caps Lock key toggled			}
{		   13	       Num Lock key toggled			}
{		   12	       Scroll Lock key toggled			}
{		   11	       Alt shift key depressed			}
{		   10	       Ctrl shift depressed			}
{		   09	       Left shift key depressed 		}
{		   08	       Right shift depressed			}
{		   07	       Ins key depressed			}
{		   06	       Caps Lock key depressed			}
{		   05	       Num Lock key depressed			}
{		   04	       Scroll Lock depressed			}
{		   03	       Suspend state toggled			}
{		   02	       SysReq depressed and held		}
{		*  01	       Left Ctrl shift depressed		}
{		*  00	       Left Alt shift depressed 		}
{									}
{		*  For Enhanced Keyboard only.				}
{									}
{	      The keyboard status is returned by accessing the key-	}
{	      board flag bytes within the BIOS communication area.	}
{	      If the Enhanced Keyboard is not attached, the enhanced	}
{	      status are set to FALSE.					}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __StatKey(var Status : _KeyStatus) : longint;

  var
    StatusLoc  : word absolute _BIOSSEG:$0017;
    StatusLoc2 : byte absolute _BIOSSEG:$0096;
    StatusWord : word;
    StatusByte : byte;

  begin {__StatKey}

    StatusWord := Swap(StatusLoc);	    { 8086 stores "backwords"	}
    StatusByte := (StatusLoc2 shr 2) and 3; { flags in 2 low order bits }

    with Status do
      begin
	_InsState    := ((StatusWord and $8000) <> 0);
	_CapsState   := ((StatusWord and $4000) <> 0);
	_NumState    := ((StatusWord and $2000) <> 0);
	_ScrollState := ((StatusWord and $1000) <> 0);
	_AltShift    := ((StatusWord and $0800) <> 0);
	_CtrlShift   := ((StatusWord and $0400) <> 0);
	_LeftShift   := ((StatusWord and $0200) <> 0);
	_RightShift  := ((StatusWord and $0100) <> 0);
	_InsShift    := ((StatusWord and $0080) <> 0);
	_CapsShift   := ((StatusWord and $0040) <> 0);
	_NumShift    := ((StatusWord and $0020) <> 0);
	_ScrollShift := ((StatusWord and $0010) <> 0);
	_HoldState   := ((StatusWord and $0008) <> 0);
	_SysShift    := ((StatusWord and $0004) <> 0);
	if (_EnhancedKbd) then
	  begin
	    _LeftAltShift   := ((StatusWord and $0002) <> 0);
	    _LeftCtrlShift  := ((StatusWord and $0001) <> 0);
	    _RightCtrlShift := ((StatusByte and $01) <> 0);
	    _RightAltShift  := ((Statusbyte and $02) <> 0)
	  end
	else
	  begin
	    _LeftAltShift   := FALSE;
	    _LeftCtrlShift  := FALSE;
	    _RightCtrlShift := FALSE;
	    _RightAltShift  := FALSE
	  end;
      end;

    __StatKey := (longint(StatusByte) shl 16) or longint(StatusWord)

  end;	{__StatKey}
