///////////////////////////////////////////////////////////////////////
// Copyright (C) Andru 2007                                          //
// mail: dr.andru@gmail.com                                          //
// site: http://andru.2x4.ru                                         //
//                                                                   //
// OMEGA Engine is free software.                                    //
//                                                                   //
// You may redistribute it and/or modify it under the terms of the   //
// GNU General Public License, as published by the Free Software     //
// Foundation; either version 2 of the License, or (at your option)  //
// any later version.                                                //
//                                                                   //
// this module is distributed in the hope that it will be useful,    //
// but WITHOUT ANY WARRANTY; without even the implied warranty of    //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              //
// See the GNU General Public License for more details.              //
//                                                                   //
// You should have received a copy of the GNU General Public License //
// along with this module.  If not, write to:                        //
// 	The Free Software Foundation, Inc.,                              //
// 	51 Franklin Street, Fifth Floor                                  //
// 	Boston, MA  02110-1301, USA.                                     //
///////////////////////////////////////////////////////////////////////
unit INPUT_KEYBOARD;

{$I DEFINES.pas}

interface
uses
  Windows,

  ENGINE_VAR;

function KeyEx_Down( KeyCode : Byte ) : Boolean; stdcall;

function Key_Down( KeyCode : Byte ) : Boolean; stdcall;
function Key_Press( KeyCode : Byte ) : Boolean; stdcall;
function Key_LastDown  : Byte; stdcall;
function Key_LastPress : Byte; stdcall;

procedure Key_LoadLayout( Layout : PChar ); stdcall;

procedure Key_BeginReadText( StartText : PChar ); stdcall;
function Key_EndReadText : PChar; stdcall;
procedure Key_MaxReadText( Count : Integer ); stdcall;

const
  K_LAYOUT_ENG = '00000409';
  K_LAYOUT_RUS = '00000419';

var
  inpK_Down  : array[ 0..255 ] of Boolean;
  inpK_Up    : array[ 0..255 ] of Boolean;
  inpK_LastD : Byte;
  inpK_LastU : Byte;

  inpK_Max   : Integer = -1;

//----------------------------------------------------------------------------//
                                 IMPLEMENTATION
//----------------------------------------------------------------------------//
function KeyEx_Down;
Begin

if GetAsyncKeyState( KeyCode ) = 0 Then
  Result := FALSE
else
  Result := TRUE;

End;

function Key_Down;
Begin

Result := inpK_Down[ KeyCode ];

End;

function Key_Press;
Begin

Result             := inpK_Up[ KeyCode ];
inpK_Up[ KeyCode ] := FALSE;

End;

function Key_LastDown;
Begin

Result := inpK_LastD;

End;

function Key_LastPress;
Begin

Result := inpK_LastU;

End;

procedure Key_LoadLayout;
Begin

LoadKeyboardLayout( Layout, KLF_ACTIVATE );

End;

procedure Key_BeginReadText;
Begin

app_Text := StartText;

End;

function Key_EndReadText;
Begin

Result := PChar( app_Text );

End;

procedure Key_MaxReadText;
Begin

inpK_Max := Count;

End;

{  K_BACKSPACE  = 8;
  K_TAB        = 9;
  K_ENTER      = 13;
  K_SHIFT      = 16;
  K_CTRL       = 17;
  K_ALT        = 18;
  K_ESCAPE     = 27;
  K_SPACE      = 32;

  K_PAGEUP     = 33;
  K_PAGEDOWN   = 34;
  K_END        = 35;
  K_HOME       = 36;
  K_SNAPSHOT   = 44;
  K_INSERT     = 45;
  K_DELETE     = 46;

  K_LEFT       = 37;
  K_UP         = 38;
  K_RIGHT      = 39;
  K_DOWN       = 40;

  K_0          = 48;
  K_1          = 49;
  K_2          = 50;
  K_3          = 51;
  K_4          = 52;
  K_5          = 53;
  K_6          = 54;
  K_7          = 55;
  K_8          = 56;
  K_9          = 57;

  K_NUMPAD0    = 96;
  K_NUMPAD1    = 97;
  K_NUMPAD2    = 98;
  K_NUMPAD3    = 99;
  K_NUMPAD4    = 100;
  K_NUMPAD5    = 101;
  K_NUMPAD6    = 102;
  K_NUMPAD7    = 103;
  K_NUMPAD8    = 104;
  K_NUMPAD9    = 105;

  K_MULTIPLY   = 106;
  K_ADD        = 107;
  K_SEPARATOR  = 108;
  K_SUBTRACT   = 109;
  K_DECIMAL    = 110;
  K_DIVIDE     = 111;

  K_A          = 65;
  K_B          = 66;
  K_C          = 67;
  K_D          = 68;
  K_E          = 69;
  K_F          = 70;
  K_G          = 71;
  K_H          = 72;
  K_I          = 73;
  K_J          = 74;
  K_K          = 75;
  K_L          = 76;
  K_M          = 77;
  K_N          = 78;
  K_O          = 79;
  K_P          = 80;
  K_Q          = 81;
  K_R          = 82;
  K_S          = 83;
  K_T          = 84;
  K_U          = 85;
  K_V          = 86;
  K_W          = 87;
  K_X          = 88;
  K_Y          = 89;
  K_Z          = 90;

  K_F1         = 112;
  K_F2         = 113;
  K_F3         = 114;
  K_F4         = 115;
  K_F5         = 116;
  K_F6         = 117;
  K_F7         = 118;
  K_F8         = 119;
  K_F9         = 120;
  K_F10        = 121;
  K_F11        = 122;
  K_F12        = 123;}

end.
