{***********************************************************************}
{									}
{ __CtrlKey   Set the keyboard status					}
{									}
{ function  __CtrlKey(Status : _KeyStatus) : longint;			}
{									}
{	      Status	The keyboard shift status record.  The keyboard }
{			flags are set to the values specified in the	}
{			record. 					}
{									}
{ Description This function sets 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 an longint, the low-order 18 bits of which	}
{	      describe which status is TRUE after the key states have	}
{	      been altered.						}
{									}
{	      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 altered by accessing the two key-	}
{	      board flag bytes within the BIOS communication area.	}
{	      The Enhanced Keyboard (101-key) sets 2 bits in another	}
{	      location of this BIOS area, and these may be set as well	}
{	      if an Enhanced keyboard is installed.			}
{									}
{	      Normally, the way to invoke __CtrlKey is first to call	}
{	      __StatKey to obtain the current flag settings, then	}
{	      alter only the flags you wish to change.			}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __CtrlKey(Status : _KeyStatus) : longint;

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

  begin {__CtrlKey}

    { First just set the bits of StatusWord and StatusByte to reflect	}
    { the request.							}

    StatusWord := 0;
    StatusByte := 0;
    with Status do
      begin
	if (_InsState) then
	   StatusWord := StatusWord or $8000;
	if (_CapsState) then
	   StatusWord := StatusWord or $4000;
	if (_NumState) then
	   StatusWord := StatusWord or $2000;
	if (_ScrollState) then
	   StatusWord := StatusWord or $1000;
	if (_AltShift) then
	   StatusWord := StatusWord or $0800;
	if (_CtrlShift) then
	   StatusWord := StatusWord or $0400;
	if (_LeftShift) then
	   StatusWord := StatusWord or $0200;
	if (_RightShift) then
	   StatusWord := StatusWord or $0100;
	if (_InsShift) then
	   StatusWord := StatusWord or $0080;
	if (_CapsShift) then
	   StatusWord := StatusWord or $0040;
	if (_NumShift) then
	   StatusWord := StatusWord or $0020;
	if (_ScrollShift) then
	   StatusWord := StatusWord or $0010;
	if (_HoldState) then
	   StatusWord := StatusWord or $0008;
	if (_SysShift) then
	   StatusWord := StatusWord or $0004;
	if (_EnhancedKbd) then			{ Additional flags for	}
	  begin 				{ the Enhanced Keyboard }
	    if (_RightCtrlShift) then
	      StatusByte := StatusByte or $08;
	    if (_RightAltShift) then
	      Statusbyte := StatusByte or $04;
	    if (_LeftCtrlshift) then
	      StatusWord := StatusWord or $0002;
	    if (_LeftAltShift) then
	      StatusWord := StatusWord or $0001
	  end;
      end;

    StatusLoc  := Swap(StatusWord);
    StatusLoc2 := StatusLoc2 or StatusByte;
    __CtrlKey  := longint(StatusWord) or (longint(StatusByte) shl 16)

  end;	{__CtrlKey}
