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

📄 adkeyed.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                    Bottom := Bottom+xSBHeight;
                    Left  := (I+2)*xSBWidth;
                  end;
        end;
        Right := Right + Left + xSBWidth;
      end;
    end;

    for I := 0 to 15 do begin
      Table[I+58].Number := I+58;
      Inc(TotalKeys, 1);
      with Table[I+58].Location do begin
        Top    := 4*xSBHeight;
        Bottom := Top + xSBHeight;
        Right := 0;
        case I of
          0     : begin
                    Left  := I*xSBWidth;
                    Right := (xSBWidth*3) div 4;
                  end;
          1..11 : Left := (I*xSBWidth)+((xSBWidth*3) div 4);
          12    : begin
                    Left  := (I*xSBWidth)+((xSBWidth*3) div 4);
                    Right := ((xSBWidth*4) div 3)-1;
                  end;
          13..15: Left  := (I+6)*xSBWidth;
        end;
        Right := Right + Left + xSBWidth;
      end;
    end;

    for I := 0 to 16 do begin
      Table[I+74].Number := I+74;
      Inc(TotalKeys, 1);
      with Table[I+74].Location do begin
        Top    := 5*xSBHeight;
        Bottom := Top + xSBHeight;
        Right := 0;
        case I of
          0     : begin
                    Left  := I*xSBWidth;
                    Right := (xSBWidth div 2) + ((xSBWidth*3) div 4);
                  end;
          1..10 : Left := (I*xSBWidth)+(xSBWidth div 2)+((xSBWidth*3) div 4);
          11    : begin
                    Left := (I*xSBWidth)+(xSBWidth div 2)+((xSBWidth*3) div 4);
                    Right := xSBWidth+((xSBWidth*4) div 5);
                  end;
          12    : Left  := (I+4)*xSBWidth+(xSBWidth div 2);
          13..15: Left  := (I+6)*xSBWidth;
          16    : begin
                    Bottom := Bottom+xSBHeight;
                    Left  := (I+6)*xSBWidth;
                  end;
        end;
        Right := Right + Left + xSBWidth;
      end;
    end;

    for I := 0 to 9 do begin
      Table[I+91].Number := I+91;
      Inc(TotalKeys, 1);
      with Table[I+91].Location do begin
        Top    := 6*xSBHeight;
        Bottom := Top + xSBHeight;
        Right := 0;
        case I of
          0     : begin
                    Left  := I*xSBWidth;
                    Right := (xSBWidth div 2);
                  end;
          1     : begin
                    Left  := ((I+1)*xSBWidth)+(xSBWidth div 2);
                    Right := (xSBWidth div 2)+1;
                  end;
          2     : begin
                    Left  := ((I+2)*xSBWidth);
                    Right := xSBWidth*6;
                  end;
          3     : begin
                    Left := ((I+8)*xSBWidth);
                    Right := (xSBWidth div 2)+1;
                  end;
          4     : begin
                    Left := ((I+9)*xSBWidth)+(xSBWidth div 2)+1;
                    Right := (xSBWidth div 2);
                  end;
          5..7  : Left  := (I+10)*xSBWidth+(xSBWidth div 2);
          8     : begin
                    Left  := (I+11)*xSBWidth;
                    Right := xSBWidth;
                  end;
          9     : Left  := (I+12)*xSBWidth;
        end;
        Right := Right + Left + xSBWidth;
      end;
    end;
    for I := 0 to TotalKeys do begin
      Table[I].KeyCode := KeyBoard101Layout[I].KeyCode;
      Table[I].Caption := KeyBoard101Layout[I].Name;
      if KeyBoard101Layout[I].KeyCode <> $00 then
        Table[I].State := bsUp
      else
        Table[I].State := bsDisabled;
    end;
  end;
end;

{---------------}

procedure TKMEditor.FormCreate(Sender: TObject);
begin
  FKeyEmuData := nil;
  FLastKeyCode := 0;
  FFileModified := False;
  KeyLayout := TKeyLayoutMap.Create(KeyboardPanel);
  KeyLayout.SetBounds(KeyboardPanel.Left+2, KeyboardPanel.Top+2,
                      KeyboardPanel.Width,  KeyboardPanel.Height);
  KeyLayout.Populate;
  KeyLayout.OnKeyClick := KeyboardKeyClick;
end;

procedure TKMEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if FKeyEmuData <> nil then
    kbDoneKeyEmulator(PKeyEmulator(FKeyEmuData));
  KeyLayout.Free;
end;

procedure TKMEditor.SetFileName(Value: String);
var
  TempFileName : Array[00..255] of char;
  TempIndex    : PChar;
begin
  if Value <> FFileName then begin
    FFileName := Value;
    if FKeyEmuData <> nil then begin
      kbDoneKeyEmulator(PKeyEmulator(FKeyEmuData));
      FKeyEmuData := nil;
      FFileModified := False;
    end;
    if kbInitKeyEmulator(PKeyEmulator(FKeyEmuData),
                         StrPCopy(TempFileName, FFileName)) = ecOK then begin
      EmuTypesTab.Tabs.Clear;
      if kbNumEmuTypes(PKeyEmulator(FKeyEmuData)) > 0 then begin
        if CheckException(Self,
              kbLoadKeyEmuIndex(PKeyEmulator(FKeyEmuData))) = ecOK then begin
          TempIndex := PKeyEmulator(FKeyEmuData)^.kbKeyNameList;
          while (TempIndex^ <> #0) do begin
            EmuTypesTab.Tabs.Add(StrPas(TempIndex));
            Inc(TempIndex, StrLen(TempIndex) + 1);
          end;
          EmuTypesTab.TabIndex := 0;
        end;
      end;
    end;
  end;
end;

function CvtCodeToStr(Value: String): String;
var
  J : Byte;
begin
  Result := '';
  for J := 1 to Length(Value) do begin
    Case Value[J] of
      #27 : Result := Result + '<ESC>';
     else
      Result := Result + Value[J];
    end;
  end;
end;

function CvtStrToCode(Value: String): String;
var
  J : Byte;
begin
  J:= Pos('<ESC>', Value);
  while J <> 0 do begin
    if J > 1 then
      Value := Copy(Value, 1, J-1)+#27+Copy(Value, J+5, Length(Value))
    else
      Value := #27+Copy(Value, J+5, Length(Value));
    J:= Pos('<ESC>', Value);
  end;
  Result := Value;
end;

procedure TKMEditor.UpdateKeymap(Code: Word; ShiftState: Byte; Map: String);
var
  EmptyKey : Word;
  Updated : Boolean;
  I : Word;
begin
  if FKeyEmuData = nil then
    Exit;
  FFileModified := True;
  with PKeyEmulator(FKeyEmuData)^ do begin
    Updated := False;
    EmptyKey := 0;
    for I := 1 to ApdMaxKeyMaps do begin                               {!!.03}
      if (Code = kbKeyMap[I].KeyCode) and (ShiftState = kbKeyMap[I].ShiftState)
      then begin
        kbKeyMap[I].Mapping := Map;
        Updated := True;
        Break;
      end else begin
        if (EmptyKey = 0) and (kbKeyMap[I].Mapping = '') then
          EmptyKey := I;
      end;
    end;
    if not Updated then begin
      if EmptyKey > 0 then begin
        kbKeyMap[EmptyKey].Mapping := Map;
        kbKeyMap[EmptyKey].KeyCode := Code;
        kbKeyMap[EmptyKey].ShiftState := ShiftState;
      end;
    end;
  end;
end;

procedure TKMEditor.KeyboardKeyClick(Sender: TObject; Code: Word; Text: String);
var
  I : Word;
begin
  if FKeyEmuData = nil then
    Exit;

  { Check for modifications of previous contents}
  NormalEditBoxExit(Self);
  CtrlKeyEditBoxExit(Self);
  CtrlAltEditBoxExit(Self);
  ShiftKeyEditBoxExit(Self);
  CtrlShiftEditBoxExit(Self);
  CtrlAltShiftEditBoxExit(Self);
                                                          
  MappingsGroupBox.Caption := 'Mappings - ['+Text+']';

  FLastKeyCode := Code;

  NormalEditBox.Text := '';
  CtrlKeyEditBox.Text := '';
  CtrlAltEditBox.Text := '';
  ShiftKeyEditBox.Text := '';
  CtrlShiftEditBox.Text := '';
  CtrlAltShiftEditBox.Text := '';

  with PKeyEmulator(FKeyEmuData)^ do begin
    for I := 1 to ApdMaxKeyMaps do begin                               {!!.03}
      with kbKeyMap[I] do begin
        if Code = KeyCode then begin
          case ShiftState of
            $0E : NormalEditBox.Text := CvtCodeToStr(Mapping);
            $0C : CtrlKeyEditBox.Text := CvtCodeToStr(Mapping);
            $08 : CtrlAltEditBox.Text := CvtCodeToStr(Mapping);
            $06 : ShiftKeyEditBox.Text := CvtCodeToStr(Mapping);
            $04 : CtrlShiftEditBox.Text := CvtCodeToStr(Mapping);
            $00 : CtrlAltShiftEditBox.Text := CvtCodeToStr(Mapping);
          end;
        end;
      end;
    end;
  end;

  NormalEditBox.Modified := False;
  CtrlKeyEditBox.Modified := False;
  CtrlAltEditBox.Modified := False;
  ShiftKeyEditBox.Modified := False;
  CtrlShiftEditBox.Modified := False;
  CtrlAltShiftEditBox.Modified := False;
end;

procedure TKMEditor.EmuTypesTabChange(Sender: TObject; NewTab: Integer;
  var AllowChange: Boolean);
var
  EmuName : TKeyMapName;
  MsgResult : Word;
begin
  KeyboardKeyClick(Self, 0, '');
  if FFileModified and (FLastKeyCode <> 0) then begin
      MsgResult := MessageDlg('The current Key Map has been modified.  Save?',
                            mtWarning, mbYesNoCancel, 0);
    case MsgResult of
      mrYes : SaveFileButtonClick(Self);
      mrCancel : begin
                   AllowChange := False;
                   Exit;
                 end;
      mrNo : FFileModified := False;
    end;
  end;
  kbSetKeyEmuType(PKeyEmulator(FKeyEmuData), StrPCopy(EmuName, EmuTypesTab.Tabs[NewTab]));
  kbLoadKeyEmuMap(PKeyEmulator(FKeyEmuData));
end;

procedure TKMEditor.NormalEditBoxExit(Sender: TObject);
begin
  if NormalEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $0E, CvtStrToCode(NormalEditBox.Text));
    NormalEditBox.Modified := False;
  end;
end;

procedure TKMEditor.CtrlKeyEditBoxExit(Sender: TObject);
begin
  if CtrlKeyEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $0C, CvtStrToCode(CtrlKeyEditBox.Text));
    CtrlKeyEditBox.Modified := False;
  end;
end;

procedure TKMEditor.ShiftKeyEditBoxExit(Sender: TObject);
begin
  if ShiftKeyEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $06, CvtStrToCode(ShiftKeyEditBox.Text));
    ShiftKeyEditBox.Modified := False;
  end;
end;

procedure TKMEditor.CtrlShiftEditBoxExit(Sender: TObject);
begin
  if CtrlShiftEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $04, CvtStrToCode(CtrlShiftEditBox.Text));
    CtrlShiftEditBox.Modified := False;
  end;
end;

procedure TKMEditor.CtrlAltEditBoxExit(Sender: TObject);
begin
  if CtrlAltEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $08, CvtStrToCode(CtrlAltEditBox.Text));
    CtrlAltEditBox.Modified := False;
  end;
end;

procedure TKMEditor.CtrlAltShiftEditBoxExit(Sender: TObject);
begin
  if CtrlAltShiftEditBox.Modified then begin
    UpdateKeyMap(FLastKeyCode, $00, CvtStrToCode(CtrlAltShiftEditBox.Text));
    CtrlAltShiftEditBox.Modified := False;
  end;
end;

procedure TKMEditor.LoadFileButtonClick(Sender: TObject);
var
  FileDialog : TOpenDialog;
  MsgResult : Word;
begin
  if FFileModified and (FLastKeyCode <> 0) then begin
    MsgResult := MessageDlg('The current Key Map has been modified.  Save?',
                            mtWarning, mbYesNoCancel, 0);
    case MsgResult of
      mrYes : SaveFileButtonClick(Self);
      mrCancel : Exit;
    end;
  end;
  FileDialog := TOpenDialog.Create(Application);
  with FileDialog do begin
    Filter := 'Keyboard DBase Files (*.INI)|*.INI|All Files (*.*)|*.*';
    Options := [ofPathMustExist, ofShowHelp];
    Title := 'Select File';
    try
      if Execute then
        SetFileName(FileName);
    finally
      Free;
    end;
  end;
end;

procedure TKMEditor.SaveFileButtonClick(Sender: TObject);
begin
  if (FKeyEmuData <> nil) and FFileModified then
    if kbUpdKeyEmuRecord(PKeyEmulator(FKeyEmuData)) = ecOK then
      FFileModified := False
end;

procedure TKMEditor.NewTypeButtonClick(Sender: TObject);
var
  NewMapName : AnsiString;
  XFerRec : TKeyMapXFerRec;
begin
  if (FKeyEmuData <> nil) then begin
    NewMapName := '';
    if InputQuery('New Key Map Name', 'Name', NewMapName) then begin
      FillChar(XFerRec, SizeOf(XFerRec), 0);
      StrPCopy(XFerRec.Name, NewMapName);
      if (kbAddKeyEmuRecord(PKeyEmulator(FKeyEmuData), XFerRec) = ecOK) then
        EmuTypesTab.Tabs.Add(NewMapName);
    end;
  end;
end;

end.


⌨️ 快捷键说明

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