📄 ikeyboard.pas
字号:
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.SetOuterMargin (const Value:Integer);begin SetIntegerProperty(Value,FOuterMargin, irtInvalidate);end;
procedure TiKeyBoard.SetSecondRowMargin(const Value:Integer);begin SetIntegerProperty(Value,FSecondRowMargin,irtInvalidate);end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.SetFont(const Value: TFont);begin FFont.Assign(Value);end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.FontChange(Sender: TObject);
var
i : Integer;
iButton : TiButton;
begin
for i := 0 to FButtonList.Count-1 do
begin
iButton := FButtonList.Objects[i] as TiButton;
iButton.Font.Assign(FFont);
end;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetStyle(const Value: TiKeyBoardStyle);
begin
if FStyle <> Value then
begin
FStyle := Value;
case FStyle of
ikbs104 : Setup104;
ikbs87 : Setup087;
ikbs74 : Setup074;
ikbs61 : Setup061;
ikbsNumericKeyPad : SetupNumericKeyPad;
end;
InvalidateChange;
end
end;
//*************************************************************************************************************************************
function TiKeyBoardButton.GetIsToggle: Boolean;
begin
case FStyle of
ikbbsStandard : Result := False;
ikbbsShift : Result := True;
ikbbsLock : Result := True;
ikbbsAccent : Result := True;
ikbbsScroll : Result := True;
ikbbsCtrl : Result := True;
ikbbsAlt : Result := True;
ikbbsNumLock : Result := True;
ikbbsSpacer : Result := False;
else Result := False;
end;
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.ButtonInvalidate(Sender: TObject);
begin
InvalidateChange;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.UnSelectAllOthers(Button: TiKeyBoardButton);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do
begin
if FButtonList.Objects[x] = Button then Continue;
if (FButtonList.Objects[x] as TiKeyBoardButton).Style <> Button.Style then Continue;
(FButtonList.Objects[x] as TiKeyBoardButton).Down := False;
end;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.UnSelectShiftCtrlAlt;
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do
begin
case (FButtonList.Objects[x] as TiKeyBoardButton).Style of
ikbbsShift, ikbbsCtrl, ikbbsAlt, ikbbsAccent : (FButtonList.Objects[x] as TiKeyBoardButton).Down := False;
end;
end;
SetShiftStatus(False);
SetCtrlStatus (False);
SetAltStatus (False);
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetLockStatus(Value: Boolean);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do (FButtonList.Objects[x] as TiKeyBoardButton).LockActive := Value
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetShiftStatus(Value: Boolean);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do (FButtonList.Objects[x] as TiKeyBoardButton).ShiftActive := Value
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetCtrlStatus(Value: Boolean);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do (FButtonList.Objects[x] as TiKeyBoardButton).CtrlActive := Value
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetAltStatus(Value: Boolean);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do (FButtonList.Objects[x] as TiKeyBoardButton).AltActive := Value
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetNumLockStatus(Value: Boolean);
var
x : Integer;
begin
for x := 0 to FButtonList.Count-1 do (FButtonList.Objects[x] as TiKeyBoardButton).NumLockActive := Value
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
Filer.DefineProperty('Buttons', ReadItems, WriteItems, DoWriteItems);
end;
//****************************************************************************************************************************************************
function TiKeyBoard.DoWriteItems: Boolean;
begin
Result := FButtonList.Count <> 0;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.WriteItems(Writer: TWriter);
var
x : Integer;
begin
TWriterAccess(Writer).WriteValue(vaCollection);
for x := 0 to FButtonList.Count-1 do
begin
Writer.WriteListBegin;
WriterWriteProperties(Writer, FButtonList.Objects[x] as TPersistent);
Writer.WriteListEnd;
end;
Writer.WriteListEnd;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.ReadItems(Reader: TReader);
var
Button : TiKeyBoardButton;
begin
RemoveAllButtons;
if not Reader.EndOfList then RemoveAllButtons;
if TReaderAccess(Reader).ReadValue <> vaCollection then exit;
while not Reader.EndOfList do
begin
Button := CreateDefaultButton;
Reader.ReadListBegin;
while not Reader.EndOfList do TReaderAccess(Reader).ReadProperty(Button);
Reader.ReadListEnd;
end;
Reader.ReadListEnd;
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.ButtonClick(Sender: TObject);
var
Button : TiKeyBoardButton;
begin
Button := Sender as TiKeyBoardButton;
case Button.Style of
ikbbsStandard : begin
UnSelectShiftCtrlAlt;
end;
ikbbsShift : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
SetShiftStatus((Sender as TiKeyBoardButton).Down);
end;
ikbbsLock : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
SetLockStatus((Sender as TiKeyBoardButton).Down);
end;
ikbbsAccent : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
end;
ikbbsScroll : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
end;
ikbbsCtrl : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
SetCtrlStatus((Sender as TiKeyBoardButton).Down);
end;
ikbbsAlt : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
SetAltStatus((Sender as TiKeyBoardButton).Down);
end;
ikbbsNumLock : begin
UnselectAllOthers(Sender as TiKeyBoardButton);
SetNumLockStatus((Sender as TiKeyBoardButton).Down);
end;
ikbbsSpacer : begin
end;
end;
end;
//*************************************************************************************************************************************
{$ifdef iVCL}
procedure TiKeyBoard.WMSetFocus(var Message: TMessage);
var
x : Integer;
begin
if not FLockFocusHandle then
begin
FFocusHandle := Message.WParam;
for x := 0 to FButtonList.Count-1 do
(FButtonList.Objects[x] as TiKeyBoardButton).FocusHandle := FFocusHandle;
end;
end;
{$endif}
//*************************************************************************************************************************************
procedure TiKeyBoard.SetFocusHandleToActiveWindow;
begin
FLockFocusHandle := True;
{$ifdef iVCL}
FocusHandle := GetActiveWindow;
{$endif}
end;
//*************************************************************************************************************************************
procedure TiKeyBoard.SetFocusHandle(const Value: Integer);
var
x : Integer;
begin
FFocusHandle := Value;
FLockFocusHandle := Value <> 0;
for x := 0 to FButtonList.Count-1 do
(FButtonList.Objects[x] as TiKeyBoardButton).FocusHandle := Value;
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.iMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : Integer;
iButton : TiKeyBoardButton;
ScreenPoint : TPoint;
begin
if (csDesigning in ComponentState) then exit;
if Button <> mbLeft then exit;
if not FLockFocusHandle then
begin
SetFocus;
{$ifdef iVCL}Windows.SetFocus(FocusHandle);{$endif}
end
else
begin
{$ifdef iVCL}Windows.SetFocus(FocusHandle);{$endif}
end;
ScreenPoint := ClientToScreen(Point(X, Y));
for i := 0 to FButtonList.Count-1 do
begin
iButton := FButtonList.Objects[i] as TiKeyBoardButton;
if not iButton.Visible then Continue;
if PtInRect(iButton.DrawRect, Point(X, Y)) then
begin
FMouseDownObject := iButton;
FMouseDownObject.iMouseDown(Button, Shift, X, Y, ScreenPoint.X, ScreenPoint.Y);
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.iMouseMove(Shift: TShiftState; X, Y: Integer);
begin
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
ScreenPoint : TPoint;
TempMouseDownObject : TiKeyBoardButton;
begin
if (csDesigning in ComponentState) then Exit;
//{$ifdef iVCL}Windows.SetFocus(FocusHandle);{$endif}
ScreenPoint := ClientToScreen(Point(X, Y));
if Assigned(FMouseDownObject) then
begin
TempMouseDownObject := FMouseDownObject;
TempMouseDownObject.iMouseUp(Button, Shift, X, Y, ScreenPoint.X, ScreenPoint.Y);
FMouseDownObject := nil;
end;
end;
//****************************************************************************************************************************************************
procedure TiKeyBoard.iDoKillFocus;
var
i : Integer;
begin
// FMouseDownObject := nil;
if (csDesigning in ComponentState) then exit;
for i := 0 to FButtonList.Count-1 do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -