⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyobj.pas

📁 维修店名称 陕西申元电子有限公司 店面地址 西安市友谊东路242号西海大厦一层 维修咨询 8008105858(免费) 或 010-64751880
💻 PAS
字号:
//
//帺暘偟偐巊傢側偄偺偱傢偐傞偲巚偆偗偳丄儊儌
//KeyObj偼TKey僋儔僗偱惗惉偟丄巊偄傑偡丅
//* Uses偵乽KeyObj乿偲乽KeyDefs乿傪壛偊傑偟傚偆丅
//* DDIDex僐儞億亅僱儞僩傪揬傝晅偗偰 Form.Create 偺偲偙傠偵 DI := DDIDex1 傪晅偗壛偊傛偆
//* 僋儔僗偺愰尵丒惗惉丒攋夡(^^;偼昁偢偡傞傛偆偵丅
//埲忋偺Step偑昁梫偱偡丅

unit KeyObj;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, MMSystem, Keydefs,DDIDex;

type
  TKeyConfig = record
  Trig1,Trig2,Trig3,Trig4,Up,Down,Left,Right : Byte;
end;

type
  TKEY = Class(Tobject)
  private
    Fleft,Fright,Fup,Fdown,Ftrig1,Ftrig2,Ftrig3,Ftrig4 : Boolean;
    Atrig1,Atrig2,Atrig3,Atrig4,Itrig1,Itrig2,Itrig3,Itrig4 : Boolean;
    Aleft,Aright,Aup,Adown,Ileft,Iright,Iup,Idown : Boolean;
    aESCtrig,bESCtrig,ESCtrig : Boolean;
    FKeyTrig1,FKeyTrig2,FKeyTrig3,FKeyTrig4,FKeyUp,FKeyDown,FKeyLeft,FKeyRight : Byte;
    KeyPush : boolean;
  public
    constructor Create;
    procedure GetKey;
    procedure LoadKeyConfig;
    procedure SaveKeyConfig;
    property Left  : Boolean read FLeft write FLeft;
    property Right : Boolean read FRight write FRight;
    property Up    : Boolean read FUp write FUp;
    property Down  : Boolean read FDown Write FDown;
    property Trig1 : Boolean read FTrig1 Write FTrig1;
    property Trig2 : Boolean read FTrig2 Write FTrig2;
    property Trig3 : Boolean read FTrig3 Write FTrig3;
    property Trig4 : Boolean read FTrig4 Write FTrig4;
    property PTrig1 : Boolean read ITrig1 write ITrig1;
    property PTrig2 : Boolean read ITrig2 write ITrig2;
    property PTrig3 : Boolean read ITrig3 write ITrig3;
    property PTrig4 : Boolean read ITrig4 write ITrig4;
    property Pleft  : Boolean read Ileft write Ileft;
    property Pright : Boolean read Iright write Iright;
    property Pup    : Boolean read Iup write Iup;
    property Pdown  : Boolean read Idown write Idown;
    property ESC    : Boolean read ESCtrig write ESCtrig;
    property AllTrig: Boolean read KeyPush write KeyPush;

    property KeyTrig1 : Byte read  FKeyTrig1
                             write FkeyTrig1;//  default VK_Z;
    property KeyTrig2 : Byte read  FKeyTrig2
                             write FkeyTrig2;//  default VK_X;
    property KeyTrig3 : Byte read  FKeyTrig3
                             write FkeyTrig3;//  default VK_C;
    property KeyTrig4 : Byte read  FKeyTrig4
                             write FkeyTrig4;//  default VK_V;
    property KeyUp    : byte read  FKeyUp
                             write FKeyup;
    property KeyDown  : byte read  FKeyDown
                             write FKeyDown;
    property KeyLeft  : byte read  FKeyLeft
                             write FKeyLeft;
    property KeyRight : byte read  FKeyRight
                             write FKeyRight;

    //destructor  Destroy;
  end;

implementation

constructor TKEY.Create;
begin
  inherited Create;
  LoadKeyConfig;
end;

procedure TKEY.GetKey;
begin
  FLeft := False; FRight := False; FUp := False; FDown := False;
  FTrig1 := False; FTrig2 := False; FTrig3 := False; FTrig4 := False;
  Itrig1 := False; Itrig2 := False; Itrig3 := False; Itrig4 := False;
  Ileft := False; Iright := false; Iup := False; Idown := False;
  ESCTrig := False; bESCtrig := False;

  //DDID偵傛傞僷僢僪擖椡
    DI.Scan(DI_JOY1);

    if (DI.Stick.Y < 0)then FUp    := True;
    if (DI.Stick.Y > 0)then FDown  := True;
    if (DI.Stick.x < 0)then FLeft  := True;
    if (DI.Stick.x > 0)then FRight := True;

    if (DI.Buttons[0] = True)then FTrig1 := True;
    if (DI.Buttons[1] = True)then FTrig2 := True;
    if (DI.Buttons[2] = True)then FTrig3 := True;
    if (DI.Buttons[3] = True)then FTrig4 := True;

  //僉亅儃亅僪
  //曽岦俲倕倷
    if ((GetAsyncKeyState(FKeyLeft)   and $8000) <> 0) then FLeft  := True;
    if ((GetAsyncKeyState(FKeyRight)  and $8000) <> 0) then FRight := True;
    if ((GetAsyncKeyState(FKeyUp)     and $8000) <> 0) then FUp    := True;
    if ((GetAsyncKeyState(FKeyDown)   and $8000) <> 0) then FDown  := True;
  //僥儞僉-
    if ((GetAsyncKeyState(VK_NUMPAD4) and $8000) <> 0) then FLeft  := True;
    if ((GetAsyncKeyState(VK_NUMPAD6) and $8000) <> 0) then FRight := True;
    if ((GetAsyncKeyState(VK_NUMPAD8) and $8000) <> 0) then FUp    := True;
    if ((GetAsyncKeyState(VK_NUMPAD2) and $8000) <> 0) then FDown  := True;
  //儃僞儞丒僩儕僈亅
    if ((GetAsyncKeyState(FKeyTrig1) and $8000) <> 0)then FTrig1 := True;
    if ((GetAsyncKeyState(FKeyTrig2) and $8000) <> 0)then FTrig2 := True;
    if ((GetAsyncKeyState(FKeyTrig3) and $8000) <> 0)then FTrig3 := True;
    if ((GetAsyncKeyState(FKeyTrig4) and $8000) <> 0)then FTrig4 := True;
    if ((GetAsyncKeyState($42) and $8000) <> 0)then FTrig1 := True;
    if ((GetAsyncKeyState($4E) and $8000) <> 0)then FTrig2 := True;
    if ((GetAsyncKeyState($4D) and $8000) <> 0)then FTrig3 := True;
  //儃僞儞丒僩儕僈亅乮僉亅僋儕僢僋幃乯
    if ((Atrig1 = False) and (Ftrig1 = True))then Itrig1 := True;
    if ((Atrig2 = False) and (Ftrig2 = True))then Itrig2 := True;
    if ((Atrig3 = False) and (Ftrig3 = True))then Itrig3 := True;
    if ((Atrig4 = False) and (Ftrig4 = True))then Itrig4 := True;
    if ((Aleft  = False) and (Fleft  = True))then Ileft  := True;
    if ((Aright = False) and (Fright = True))then Iright := True;
    if ((Aup    = False) and (Fup    = True))then Iup    := True;
    if ((Adown  = False) and (Fdown  = True))then Idown  := True;
  //ESC
    if ((GetAsyncKeyState($1B) and $8000) <> 0)then bESCtrig := True;
    if ((aESCtrig = False) and (bEsctrig = True))then ESCtrig := True;
  //偳傟偐Key傪墴偟偨偐
    KeyPush := False;
    KeyPush := FTrig1 or FTrig2 or FTrig3 or FTrig4 or bEscTrig;


  Atrig1 := Ftrig1;  Atrig2 := Ftrig2;
  Atrig3 := Ftrig3;  Atrig4 := Ftrig4;
  Aleft  := Fleft;   Aright := Fright;
  Aup    := Fup;     Adown  := Fdown;
  aESCtrig := bESCtrig;
  end;

procedure TKey.SaveKeyConfig;
var
  ff : file;
  KeyCon : TKeyConfig;
begin
  KeyCon.Trig1 := FKeyTrig1;
  KeyCon.Trig2 := FKeyTrig2;
  KeyCon.Trig3 := FKeyTrig3;
  KeyCon.Trig4 := FKeyTrig4;
  KeyCon.Up   := FKeyUp;
  KeyCon.Down := FKeyDown;
  KeyCon.Left := FkeyLeft;
  KeyCon.Right:= FKeyRight;

  assignfile(ff,'KeyCon.dat');
  ReWrite(ff,1);
  blockWrite(ff,KeyCon,8);
  closefile(ff);
end;


procedure TKey.LoadKeyConfig;
var
  ff : file;
  KeyCon : TKeyConfig;
begin
   if (FileExists('KeyCon.Dat') = True)then
  begin
    assignfile(ff,'KeyCon.dat');
    Reset(ff,1);
    blockread(ff,KeyCon,8);
    closefile(ff);
  end
  else
  begin
    KeyCon.trig1 := $5A;  //z
    KeyCon.trig2 := $58;  //x
    KeyCon.trig3 := $43;  //c
    KeyCon.trig4 := $56;  //v
    KeyCon.up    := $26;  //僇亅僜儖僉亅
    KeyCon.down  := $28;
    KeyCon.left  := $25;
    KeyCon.right := $27;
  end;

  FKeyTrig1 := KeyCon.Trig1;
  FKeyTrig2 := KeyCon.Trig2;
  FKeyTrig3 := KeyCon.Trig3;
  FKeyTrig4 := KeyCon.Trig4;
  FKeyUp    := KeyCon.Up;
  FKeyDown  := KeyCon.Down;
  FkeyLeft  := KeyCon.Left;
  FKeyRight := KeyCon.Right;

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -