📄 hkedit.pas
字号:
chkCtrl.Checked := Pos('Ctrl', sHotkey)>0;
chkAlt.Checked := Pos('Alt', sHotkey)>0;
chkShift.Checked := Pos('Shift', sHotkey)>0;
chkWin.Checked := Pos('Win', sHotkey)>0;
while Pos('+', sHotkey)>0 do Delete(sHotkey, 1, Pos('+', sHotkey));
if sHotkey<>'' then
cboHotkey.ItemIndex := cboHotkey.Items.IndexOf(sHotkey)
else
cboHotkey.ItemIndex := -1;
end;
end;
procedure TfrmHotkeyEdit.FormCreate(Sender: TObject);
var
i : integer;
IniFile: String;
begin
Application.ShowMainForm := False;
if FindWindow('Shell_TrayWnd', nil)=0 then WindowState := wsMinimized;
atiHotkeys.HideAppIcon;
for i:= Low(Actions) to High(Actions) do cboActions.Items.Add(Actions[i]);
for i:= Low(Params) to High(Params) do cboParams.Items.Add(Params[i]);
cboParams.ItemIndex := 0;
Quitting := False;
Ignore := False;
cboShow.ItemIndex := 0;
Clipboards := TClipboards.Create;
hwndClipViewer := SetClipboardViewer(Handle);
CommandLines := TStringList.Create;
WindowList := TList.Create;
IniFile := ChangeFileExt(Application.ExeName, '.ini');
WindowState := wsNormal;
with TInifile.Create(IniFile) do
begin
chkShowIcon.Checked := ReadInteger('Settings', 'ShowTaskbarIcon', 1)=1;
chkShowIconClick(Self);
Ignore := True;
udClipboards.Position := ReadInteger('Settings', 'ClipboardCount', 5);
edtClipboards.Text := IntToStr(udClipboards.Position);
Ignore := False;
Width := ReadInteger('EditorWindow', 'Width', Width);
Height := ReadInteger('EditorWindow', 'Height', Height);
for i:=0 to lvHotkeys.Columns.Count-1 do
with lvHotkeys.Columns[i] do
Width := ReadInteger('EWColumns', Caption, Width);
Free;
end;
SetClipboards;
SwitchToClipboard(0);
ReadHotkeys;
LoadHotkeys;
end;
procedure TfrmHotkeyEdit.SetClipboards;
var
sClip: String;
i : integer;
begin
Clipboards.NumClipboards := udClipboards.Position;
sClip := cboClipboard.Text;
cboClipboard.Clear;
for i:=1 to Clipboards.NumClipboards do cboClipboard.Items.Add(IntToStr(i));
cboClipboard.ItemIndex := cboClipboard.Items.IndexOf(sClip);
if cboClipboard.ItemIndex=-1 then cboClipboard.ItemIndex := 0;
end;
function TfrmHotkeyEdit.ReadHotkey(Reader: TReader): String;
begin
Result := '';
if Reader.ReadBoolean then AddTo(Result, 'Ctrl');
if Reader.ReadBoolean then AddTo(Result, 'Alt');
if Reader.ReadBoolean then AddTo(Result, 'Shift');
if Reader.ReadBoolean then AddTo(Result, 'Win');
AddTo(Result, cboHotKey.Items[Reader.ReadInteger]);
end;
procedure TfrmHotkeyEdit.ReadHotkeys;
var
Stream : TFileStream;
Reader : TReader;
sVersion : String;
iVersion : Integer;
Action,
Index : Integer;
begin
if Item<>nil then Index := Item.Index else Index := 0;
lvHotkeys.Items.BeginUpdate;
try
Stream := TFileStream.Create(ChangeFileExt(Application.ExeName, '.HKD'), fmOpenRead);
try
Reader := TReader.Create(Stream, 4096);
try
lvHotkeys.Items.Clear;
sVersion := Reader.ReadString;
iVersion := 120;
if sVersion = 'Hotkey definitions, version 1.0' then iVersion := 100;
if sVersion = 'Hotkey definitions, version 1.05' then iVersion := 105;
Reader.ReadListBegin;
while not Reader.EndOfList do
begin
Item := lvHotkeys.Items.Add;
Item.Caption := Reader.ReadString;
if iVersion=100 then Item.SubItems.Add(MakeID(lvHotkeys, Item, Item.Caption)) else Item.SubItems.Add(Reader.ReadString);
Action := Reader.ReadInteger;
if (iVersion=100) and (Action>1) then inc(Action);
Item.SubItems.Add(cboActions.Items[Action]);
case Action of
0, 1, 2: Item.SubItems.Add(Reader.ReadString);
3 : Item.SubItems.Add(cboParams.Items[Reader.ReadInteger]);
10 : Item.SubItems.Add(cboClipboard.Items[Reader.ReadInteger]);
else Item.SubItems.Add('');
end;
Item.SubItems.Add(ReadHotkey(Reader));
Item.SubItems.Add(Actives[Reader.ReadBoolean]);
if (Action=0) then
begin
if (iVersion=120) then
Item.SubItems.Add(Reader.ReadString)
else
Item.SubItems.Add(cboShow.Items[0]);
end;
end;
Reader.ReadListEnd;
finally
Reader.Free;
end;
finally
Stream.Free;
end;
except
end;
if lvHotkeys.Items.Count=0 then
btnNewClick(Self)
else
begin
lvHotkeys.Selected := lvHotkeys.Items[Index];
lvHotkeysClick(Self);
IsChanged := False;
end;
lvHotkeys.Items.EndUpdate;
end;
procedure TfrmHotkeyEdit.SaveHotkeys;
var
Stream: TFileStream;
Writer: TWriter;
i,
Index : Integer;
Hotkey: String;
begin
try
Stream := TFileStream.Create(ChangeFileExt(Application.ExeName, '.HKD'), fmCreate);
try
Writer := TWriter.Create(Stream, 4096);
try
Writer.WriteString('Hotkey definitions, version 1.2');
Writer.WriteListBegin;
with lvHotkeys do
for i:=0 to Items.Count-1 do
begin
Writer.WriteString(Items[i].Caption);
Writer.WriteString(Items[i].SubItems[ITEM_ID]);
Index := cboActions.Items.IndexOf(Items[i].SubItems[ITEM_ACTION]);
Writer.WriteInteger(Index);
case Index of
0, 1, 2: Writer.WriteString(Items[i].SubItems[ITEM_DATA]);
3 : Writer.WriteInteger(cboParams.Items.IndexOf(Items[i].SubItems[ITEM_DATA]));
10 : Writer.WriteInteger(cboClipboard.Items.IndexOf(Items[i].SubItems[ITEM_DATA]));
end;
Hotkey := Items[i].SubItems[ITEM_HOTKEY];
Writer.WriteBoolean(Pos('Ctrl', Hotkey)>0);
Writer.WriteBoolean(Pos('Alt', Hotkey)>0);
Writer.WriteBoolean(Pos('Shift', Hotkey)>0);
Writer.WriteBoolean(Pos('Win', Hotkey)>0);
while Pos('+', Hotkey)>0 do Delete(Hotkey, 1, Pos('+', Hotkey));
Writer.WriteInteger(cboHotkey.Items.IndexOf(Hotkey));
Writer.WriteBoolean(Items[i].SubItems[ITEM_ACTIVE]=Actives[True]);
if (Index=0) then Writer.WriteString(Items[i].SubItems[ITEM_SHOW]);
end;
Writer.WriteListEnd;
finally
Writer.Free;
end;
finally
Stream.Free;
end;
except
end;
IsChanged := False;
LoadHotkeys;
if Assigned(frmHotkeyList) and (frmHotkeyList.Visible) then frmHotkeyList.ReadHotkeys;
end;
procedure TfrmHotkeyEdit.btnDeleteClick(Sender: TObject);
begin
if Item<>nil then
begin
Item.Free;
if lvHotkeys.Items.Count>0 then
begin
lvHotkeys.Selected := lvHotkeys.Items[0];
lvHotkeysClick(Self);
IsChanged := True;
end
else
btnNewClick(Self);
end;
end;
procedure TfrmHotkeyEdit.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmHotkeyEdit.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if IsChanged then
case Application.MessageBox('Hotkey definitions have changed. Save changes?', 'Hotkey Editor', MB_ICONQUESTION or MB_YESNOCANCEL) of
IDYES: SaveHotkeys;
IDNO : begin
IsChanged := False;
ReadHotkeys;
LoadHotkeys;
end;
IDCANCEL: CanClose := False;
end;
end;
procedure TfrmHotkeyEdit.LoadHotkeys;
var
Stream : TFileStream;
Reader : TReader;
Action : Integer;
sVersion : String;
iVersion : Integer;
sDescription,
sID,
sHotkey,
sCommandLine : String;
Item : TMenuItem;
begin
with SysHotkeys do
begin
try
try
Stream := TFileStream.Create(ChangeFileExt(Application.ExeName, '.HKD'), fmOpenRead);
try
Reader := TReader.Create(Stream, 4096);
try
CommandLines.Clear;
mnuEditHotkeys.Caption := '&Edit hotkeys...';
mnuListHotkeys.Caption := '&View hotkey list...';
mnuAbout.Caption := '&About...';
mnuHelp.Caption := 'Hotkeys &Help';
while mnuHotkeys.Count>0 do mnuHotkeys.Items[0].Free;
Clear;
sVersion := Reader.ReadString;
iVersion := 120;
if sVersion = 'Hotkey definitions, version 1.0' then iVersion:=100;
if sVersion = 'Hotkey definitions, version 1.05' then iVersion:=105;
Reader.ReadListBegin;
while not Reader.EndOfList do
begin
sDescription := Reader.ReadString; // Hotkey description
if (iVersion>100) then sID := Reader.ReadString;
Action := Reader.ReadInteger;
if (iVersion=100) and (Action>1) then inc(Action);
case Action of
0, 1, 2: sCommandLine := Reader.ReadString; // Commandline
3 : sCommandLine := IntToStr(Reader.ReadInteger); // Parameter
10 : sCommandLine := IntToStr(Reader.ReadInteger); // Clipboard
end;
sHotkey := ReadHotkey(Reader);
if Reader.ReadBoolean and ((Action>1) or (sCommandLine<>'')) then
begin
if (Action=0) then
begin
if (iVersion=120) then
CommandLines.Add(IntToStr(Action) + '=' + sCommandLine+';'+Reader.ReadString)
else
CommandLines.Add(IntToStr(Action) + '=' + sCommandLine+';'+cboShow.Items[0]);
end
else
CommandLines.Add(IntToStr(Action) + '=' + sCommandLine);
AddHotkey(Virtkey(sHotkey), Modifiers(sHotkey));
case Action of
0,2: begin
Item := NewItem(sDescription+#9+sHotkey, 0, False, True, HotkeyMenuClick, 0, '');
Item.Tag := CommandLines.Count-1;
mnuHotkeys.Add(Item);
end;
4: mnuEditHotkeys.Caption := '&Edit hotkeys...'+#9+sHotkey;
5: mnuListHotkeys.Caption := '&View hotkey list...'+#9+sHotkey;
6: mnuAbout.Caption := '&About...'+#9+sHotkey;
7: mnuHelp.Caption := 'Hotkeys &Help'+#9+sHotkey;
end;
end;
end;
Reader.ReadListEnd;
finally
Reader.Free;
end;
finally
Stream.Free;
end;
finally
mnuHotkeys.Visible := mnuHotkeys.Count>0;
mnuSeparator1.Visible := mnuHotkeys.Count>0;
end;
except
end;
end;
end;
function TfrmHotkeyEdit.VirtKey(sHotkey: String): TVirtKey;
begin
Result := vkNone;
while Pos('+', sHotkey)>0 do Delete(sHotkey, 1, Pos('+', sHotkey));
case cboHotKey.Items.IndexOf(sHotkey) of
0: Result := vkBack; // Backspace
1: Result := vkTab; // Tab
2: Result := vkReturn; // Return
3: Result := vkPause; // Pause
4: Result := vkCapital; // Capslock
5: Result := vkEscape; // Escape
6: Result := vkSpace; // Space
7: Result := vkPrior; // PgUp
8: Result := vkNext; // PgDn
9: Result := vkHome; // Home
10: Result := vkEnd; // End
11: Result := vkLeft; // Left Arrow
12: Result := vkUp; // Up Arrow
13: Result := vkRight; // Right Arrow
14: Result := vkDown; // Down Arrow
15: Result := vkSnapshot; // PrintScreen
16: Result := vkInsert; // Insert
17: Result := vkDelete; // Delete
18: Result := vk0; // 0
19: Result := vk1; // 1
20: Result := vk2; // 2
21: Result := vk3; // 3
22: Result := vk4; // 4
23: Result := vk5; // 5
24: Result := vk6; // 6
25: Result := vk7; // 7
26: Result := vk8; // 8
27: Result := vk9; // 9
28: Result := vkA; // A
29: Result := vkB; // B
30: Result := vkC; // C
31: Result := vkD; // D
32: Result := vkE; // E
33: Result := vkF; // F
34: Result := vkG; // G
35: Result := vkH; // H
36: Result := vkI; // I
37: Result := vkJ; // J
38: Result := vkK; // K
39: Result := vkL; // L
40: Result := vkM; // M
41: Result := vkN; // N
42: Result := vkO; // O
43: Result := vkP; // P
44: Result := vkQ; // Q
45: Result := vkR; // R
46: Result := vkS; // S
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -