home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
desktop
/
hotkey
/
hotkey95.exe
/
Source
/
hkEdit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-02-20
|
28KB
|
893 lines
unit hkEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, WComp, SysHot, ShellAPI, AniTray, Menus, ExtCtrls, IniFiles,
Buttons, BrowseEdit;
const
WM_EDITKEYS = WM_USER+2001;
WM_SENDKEYS = WM_USER+2002;
type
TfrmHotkeyEdit = class(TForm)
lvHotkeys: TListView;
SysHotkeys: TSysHotKey;
ppmTrayMenu: TPopupMenu;
mnuEditHotkeys: TMenuItem;
mnuAbout: TMenuItem;
mnuSeparator2: TMenuItem;
mnuExit: TMenuItem;
atiHotkeys: TAnimatedTrayIcon;
pnlControls: TPanel;
pnlEdit: TPanel;
pnlButtons: TPanel;
btnNew: TButton;
btnDelete: TButton;
btnApply: TButton;
btnClose: TButton;
grpHotkey: TGroupBox;
lblDescription: TLabel;
lblCommandLine: TLabel;
lblHotkey: TLabel;
edtDescription: TEdit;
chkCtrl: TCheckBox;
chkAlt: TCheckBox;
chkShift: TCheckBox;
chkWin: TCheckBox;
cboHotkey: TComboBox;
chkActive: TCheckBox;
mnuListHotkeys: TMenuItem;
pnlOptions: TPanel;
chkShowIcon: TCheckBox;
mnuSeparator1: TMenuItem;
mnuHotkeys: TMenuItem;
lblAction: TLabel;
cboActions: TComboBox;
edtCommandLine: TBrowseEdit;
cboParams: TComboBox;
mnuHelp: TMenuItem;
mnuSeparator0: TMenuItem;
edtKeysToSend: TEdit;
opdOpenFile: TOpenDialog;
procedure btnNewClick(Sender: TObject);
procedure chkActiveClick(Sender: TObject);
procedure edtDescriptionChange(Sender: TObject);
procedure edtCommandLineChange(Sender: TObject);
procedure chkCtrlClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lvHotkeysClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SysHotkeysHotKey(Sender: TObject; Index: Integer);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure mnuEditHotkeysClick(Sender: TObject);
procedure mnuExitClick(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure atiHotkeysEndAnimation(Sender: TObject);
procedure mnuAboutClick(Sender: TObject);
procedure mnuListHotkeysClick(Sender: TObject);
procedure chkShowIconClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cboActionsClick(Sender: TObject);
procedure cboParamsClick(Sender: TObject);
procedure edtKeysToSendChange(Sender: TObject);
procedure mnuHelpClick(Sender: TObject);
private
Item: TListItem;
FChanged: Boolean;
Quitting, Ignore: Boolean;
CurModifiers: THKModifiers;
CurVirtKey : TVirtKey;
CommandLines: TStringList;
procedure SetChanged(Value: Boolean);
function HotkeyOK(sHotkey: String): Boolean;
procedure SetControls;
protected
property IsChanged: Boolean read FChanged write SetChanged;
procedure EditHotkeys;
procedure ViewHotkeys;
procedure AboutBox;
procedure HelpIndex;
function VirtKey(sHotkey: String): TVirtKey;
function Modifiers(sHotkey: String): THKModifiers;
procedure AddTo(var sKey: String; Value: String);
procedure SetItem;
procedure GetHotkey;
procedure SetHotkey;
procedure ReadHotkeys;
procedure SaveHotkeys;
procedure LoadHotkeys;
procedure wmGetMinMaxInfo(var Msg: TWMGETMINMAXINFO); message WM_GETMINMAXINFO;
procedure wmEditKeys(var Msg: TMessage); message WM_EDITKEYS;
procedure wmSendKeys(var Msg: TMessage); message WM_SENDKEYS;
public
function ReadHotkey(Reader: TReader): String;
procedure HotkeyMenuClick(Sender: TObject);
procedure HotkeyPressed(Index: Integer);
end;
var
frmHotkeyEdit: TfrmHotkeyEdit;
implementation
{$R *.DFM}
uses hkAbout, hkList, hkError, hkSend;
const
Actives : array[Boolean] of string = ('False', 'True');
Params : array[0..2] of String = ('Shutdown', 'Log off', 'Reboot');
Actions : array[0..6] of String = ('Execute Program', 'Send keystrokes',
'Exit Windows', 'Edit Hotkeys',
'View Hotkeys', 'Display About Box',
'Hotkeys Help');
ITEM_ACTION = 0;
ITEM_DATA = 1;
ITEM_HOTKEY = 2;
ITEM_ACTIVE = 3;
procedure TfrmHotkeyEdit.lvHotkeysClick(Sender: TObject);
begin
if lvHotkeys.Selected<>nil then
begin
Item := lvHotkeys.Selected;
grpHotkey.Caption := 'Edit hotkey';
SetItem;
end
else if Item<>nil then lvHotkeys.Selected := Item;
end;
procedure TfrmHotkeyEdit.btnNewClick(Sender: TObject);
begin
Item := lvHotkeys.Items.Add;
Item.SubItems.Add(cboActions.Items[0]);
Item.SubItems.Add('');
Item.SubItems.Add('');
Item.SubItems.Add('True');
grpHotkey.Caption := 'Add hotkey';
SetItem;
lvHotkeys.Selected := Item;
IsChanged := True;
end;
procedure TfrmHotkeyEdit.SetItem;
begin
Ignore := True;
edtDescription.Text := Item.Caption;
cboActions.ItemIndex := cboActions.Items.IndexOf(Item.SubItems[ITEM_ACTION]);
case cboActions.ItemIndex of
0 : edtCommandLine.Text := Item.SubItems[ITEM_DATA];
1 : edtKeysToSend.Text := Item.SubItems[ITEM_DATA];
2 : cboParams.ItemIndex := cboParams.Items.IndexOf(Item.SubItems[ITEM_DATA]);
end;
SetControls;
SetHotkey;
chkActive.Checked := (Item.SubItems[ITEM_ACTIVE] = 'True');
Ignore := False;
end;
procedure TfrmHotkeyEdit.chkActiveClick(Sender: TObject);
begin
if (Item<>nil) and not Ignore then
begin
if chkActive.Checked then Item.SubItems[ITEM_ACTIVE] := 'True' else Item.SubItems[ITEM_ACTIVE] := 'False';
IsChanged := True;
end;
end;
procedure TfrmHotkeyEdit.edtDescriptionChange(Sender: TObject);
begin
if (Item<>nil) and not Ignore then
begin
Item.Caption := edtDescription.Text;
IsChanged := True;
end;
end;
procedure TfrmHotkeyEdit.edtCommandLineChange(Sender: TObject);
begin
if (Item<>nil) and not Ignore then
begin
Item.SubItems[ITEM_DATA] := edtCommandLine.Text;
IsChanged := True;
end;
end;
procedure TfrmHotkeyEdit.chkCtrlClick(Sender: TObject);
begin
GetHotkey;
end;
procedure TfrmHotkeyEdit.AddTo(var sKey: String; Value: String);
begin
if sKey<>'' then sKey := sKey + '+';
sKey := sKey + Value;
end;
function TfrmHotkeyEdit.HotkeyOK(sHotkey: String): Boolean;
const
ErrorDescription = 'If you continue the hotkey combination for ''%s'' will not work.';
var
i: Integer;
begin
with lvHotkeys do
for i:=0 to Items.Count-1 do
if (Items[i]<>Item) and (Items[i].SubItems[ITEM_HOTKEY]=sHotkey) and (Items[i].SubItems[ITEM_ACTIVE]='True') then
with frmHotkeyError do
begin
ConflictingEntry := Items[i].Caption;
if Items[i].Index<Item.Index then
Description := Format(ErrorDescription, [Items[i].Caption])
else
Description := Format(ErrorDescription, [Item.Caption]);
Result := ShowModal = mrOk;
Exit;
end;
if not SysHotkeys.AddHotkey(Virtkey(sHotkey), Modifiers(sHotkey)).Registered then
begin
MessageBox(Handle, 'This hotkey combination is in use by another application.', 'Hotkey combination error', MB_ICONINFORMATION or MB_OK);
Result := False;
end
else
Result := True;
SysHotkeys.Delete(SysHotkeys.HotkeyCount-1);
end;
procedure TfrmHotkeyEdit.GetHotkey;
var
sHotkey: String;
begin
sHotkey := '';
if (Item<>nil) and not Ignore then
begin
if chkCtrl.Checked then AddTo(sHotkey, 'Ctrl');
if chkAlt.Checked then AddTo(sHotkey, 'Alt');
if chkShift.Checked then AddTo(sHotkey, 'Shift');
if chkWin.Checked then AddTo(sHotkey, 'Win');
AddTo(sHotkey, cboHotkey.Items[cboHotkey.ItemIndex]);
if HotkeyOk(sHotkey) then
begin
Item.SubItems[ITEM_HOTKEY] := sHotkey;
IsChanged := True;
end
else
SetHotkey;
end;
end;
procedure TfrmHotkeyEdit.SetHotkey;
var
sHotkey: String;
begin
if Item<>nil then
begin
sHotkey := Item.SubItems[ITEM_HOTKEY];
CurVirtkey := VirtKey(sHotkey);
CurModifiers := Modifiers(sHotkey);
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;
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;
CommandLines := TStringList.Create;
ReadHotkeys;
LoadHotkeys;
IniFile := ChangeFileExt(Application.ExeName, '.ini');
WindowState := wsNormal;
with TInifile.Create(IniFile) do
begin
chkShowIcon.Checked := ReadInteger('Settings', 'ShowTaskbarIcon', 1)=1;
chkShowIconClick(Self);
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;
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;
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;
Reader.ReadString; // version
Reader.ReadListBegin;
while not Reader.EndOfList do
begin
Item := lvHotkeys.Items.Add;
Item.Caption := Reader.ReadString;
Action := Reader.ReadInteger;
Item.SubItems.Add(cboActions.Items[Action]);
case Action of
0, 1: Item.SubItems.Add(Reader.ReadString);
2 : Item.SubItems.Add(cboParams.Items[Reader.ReadInteger]);
else Item.SubItems.Add('');
end;
Item.SubItems.Add(ReadHotkey(Reader));
Item.SubItems.Add(Actives[Reader.ReadBoolean]);
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.0');
Writer.WriteListBegin;
with lvHotkeys do
for i:=0 to Items.Count-1 do
begin
Writer.WriteString(Items[i].Caption);
Index := cboActions.Items.IndexOf(Items[i].SubItems[ITEM_ACTION]);
Writer.WriteInteger(Index);
case Index of
0, 1: Writer.WriteString(Items[i].SubItems[ITEM_DATA]);
2 : Writer.WriteInteger(cboParams.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]);
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;
sDescription,
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;
Reader.ReadString; // version
Reader.ReadListBegin;
while not Reader.EndOfList do
begin
sDescription := Reader.ReadString; // Hotkey description
Action := Reader.ReadInteger;
case Action of
0, 1: sCommandLine := Reader.ReadString; // Commandline
2 : sCommandLine := IntToStr(Reader.ReadInteger); // Parameter
end;
sHotkey := ReadHotkey(Reader);
if Reader.ReadBoolean and ((Action>1) or (sCommandLine<>'')) then
begin
CommandLines.Add(IntToStr(Action) + '=' + sCommandLine);
AddHotkey(Virtkey(sHotkey), Modifiers(sHotkey));
case Action of
0: begin
Item := NewItem(sDescription+#9+sHotkey, 0, False, True, HotkeyMenuClick, 0, '');
Item.Tag := CommandLines.Count-1;
mnuHotkeys.Add(Item);
end;
3: mnuEditHotkeys.Caption := '&Edit hotkeys...'+#9+sHotkey;
4: mnuListHotkeys.Caption := '&View hotkey list...'+#9+sHotkey;
5: mnuAbout.Caption := '&About...'+#9+sHotkey;
6: 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
47: Result := vkT; // T
48: Result := vkU; // U
49: Result := vkV; // V
50: Result := vkW; // W
51: Result := vkX; // X
52: Result := vkY; // Y
53: Result := vkZ; // Z
54: Result := vkNumpad0; // Num 0
55: Result := vkNumpad1; // Num 1
56: Result := vkNumpad2; // Num 2
57: Result := vkNumpad3; // Num 3
58: Result := vkNumpad4; // Num 4
59: Result := vkNumpad5; // Num 5
60: Result := vkNumpad6; // Num 6
61: Result := vkNumpad7; // Num 7
62: Result := vkNumpad8; // Num 8
63: Result := vkNumpad9; // Num 9
64: Result := vkMultiply; // Num *
65: Result := vkAdd; // Num +
66: Result := vkSubtract; // Num -
67: Result := vkDecimal; // Num .
68: Result := vkDivide; // Num /
69: Result := vkF1; // F1
70: Result := vkF2; // F2
71: Result := vkF3; // F3
72: Result := vkF4; // F4
73: Result := vkF5; // F5
74: Result := vkF6; // F6
75: Result := vkF7; // F7
76: Result := vkF8; // F8
77: Result := vkF9; // F9
78: Result := vkF10; // F10
79: Result := vkF11; // F11
80: Result := vkF12; // F12
81: Result := vkF13; // F13
82: Result := vkF14; // F14
83: Result := vkF15; // F15
84: Result := vkF16; // F16
85: Result := vkF17; // F17
86: Result := vkF18; // F18
87: Result := vkF19; // F19
88: Result := vkF20; // F20
89: Result := vkF21; // F21
90: Result := vkF22; // F22
91: Result := vkF23; // F23
92: Result := vkF24; // F24
93: Result := vkNumlock; // Numlock
94: Result := vkScroll; // Scrolllock
end;
end;
function TfrmHotkeyEdit.Modifiers(sHotkey: String): THKModifiers;
begin
Result := [];
if Pos('Ctrl', sHotkey) > 0 then Include(Result, hkCtrl);
if Pos('Alt', sHotkey) > 0 then Include(Result, hkAlt);
if Pos('Shift', sHotkey) > 0 then Include(Result, hkShift);
if Pos('Win', sHotkey) > 0 then Include(Result, hkExt);
end;
procedure TfrmHotkeyEdit.SysHotkeysHotKey(Sender: TObject; Index: Integer);
begin
HotkeyPressed(Index);
end;
procedure TfrmHotkeyEdit.FormDestroy(Sender: TObject);
var
i : integer;
begin
CommandLines.Free;
with TInifile.Create(ChangeFileExt(Application.ExeName, '.ini')) do
begin
WriteInteger('EditorWindow', 'Width', Width);
WriteInteger('EditorWindow', 'Height', Height);
for i:=0 to lvHotkeys.Columns.Count-1 do
with lvHotkeys.Columns[i] do
WriteInteger('EWColumns', Caption, Width);
Free;
end;
end;
procedure TfrmHotkeyEdit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not Quitting then
begin
Action := caNone;
Hide;
end;
end;
procedure TfrmHotkeyEdit.mnuEditHotkeysClick(Sender: TObject);
begin
EditHotkeys;
end;
procedure TfrmHotkeyEdit.wmEditKeys(var Msg: TMessage);
begin
if Msg.wParam = WM_EDITKEYS then EditHotkeys;
end;
procedure TfrmHotkeyEdit.EditHotkeys;
begin
WindowState := wsNormal;
Show;
SetWindowPos(Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
SetForeGroundWindow(Handle);
end;
procedure TfrmHotkeyEdit.mnuExitClick(Sender: TObject);
begin
Quitting := True;
Close;
end;
procedure TfrmHotkeyEdit.SetChanged(Value: Boolean);
begin
if FChanged<>Value then
begin
FChanged := Value;
if FChanged then SysHotkeys.Clear;
btnApply.Enabled := FChanged;
end;
end;
procedure TfrmHotkeyEdit.btnApplyClick(Sender: TObject);
begin
SaveHotkeys;
end;
procedure TfrmHotkeyEdit.FormResize(Sender: TObject);
begin
cboHotkey.Width := ClientWidth - 376;
edtDescription.Width := ClientWidth - 184;
edtKeysToSend.Width := ClientWidth - 184;
cboActions.Width := ClientWidth - 184;
cboParams.Width := ClientWidth - 184;
edtCommandLine.Width := ClientWidth - 184;
end;
procedure TfrmHotkeyEdit.wmGetMinMaxInfo(var Msg: TWMGETMINMAXINFO);
begin
Msg.MinMaxInfo^.ptMinTrackSize.X := 411;
Msg.MinMaxInfo^.ptMinTrackSize.Y := 244;
end;
procedure TfrmHotkeyEdit.atiHotkeysEndAnimation(Sender: TObject);
begin
atiHotkeys.Style := tsNormal;
end;
procedure TfrmHotkeyEdit.mnuAboutClick(Sender: TObject);
begin
AboutBox;
end;
procedure TfrmHotkeyEdit.AboutBox;
begin
frmAbout.Show;
SetForeGroundWindow(frmAbout.Handle);
end;
procedure TfrmHotkeyEdit.ViewHotkeys;
begin
frmHotkeyList.Show;
SetForeGroundWindow(frmHotkeyList.Handle);
end;
procedure TfrmHotkeyEdit.mnuListHotkeysClick(Sender: TObject);
begin
ViewHotkeys;
end;
procedure TfrmHotkeyEdit.HotkeyMenuClick(Sender: TObject);
begin
HotkeyPressed(TMenuItem(Sender).Tag);
end;
procedure TfrmHotkeyEdit.HotkeyPressed(Index: Integer);
const
Flags: array[0..2] of integer = (EWX_SHUTDOWN, EWX_LOGOFF, EWX_REBOOT);
var
Action : Integer;
Command: String;
begin
if Index>CommandLines.Count then Exit;
if CommandLines[Index]<>'' then
begin
atiHotkeys.Style := tsAnimated;
Action := StrToInt(CommandLines[Index][1]);
Command := Copy(CommandLines[Index], 3, Length(CommandLines[Index]));
case Action of
0: WinExec(PChar(Command), SW_SHOW);
1: PostMessage(Handle, WM_SENDKEYS, WM_SENDKEYS, Index);
2: ExitWindowsEx(Flags[StrToInt(Command)], 0);
3: EditHotkeys;
4: ViewHotkeys;
5: AboutBox;
6: HelpIndex;
end;
end;
end;
procedure TfrmHotkeyEdit.wmSendKeys(var Msg: TMessage);
var
Keys: String;
begin
if Msg.wParam=WM_SENDKEYS then
begin
Keys := CommandLines[Msg.lParam];
Delete(Keys,1, 2);
SendKeys(Keys);
end;
end;
procedure TfrmHotkeyEdit.chkShowIconClick(Sender: TObject);
begin
atiHotkeys.Active := chkShowIcon.Checked;
with TInifile.Create(ChangeFileExt(Application.ExeName, '.ini')) do
begin
if chkShowIcon.Checked then
WriteInteger('Settings', 'ShowTaskbarIcon', 1)
else
WriteInteger('Settings', 'ShowTaskbarIcon', 0);
Free;
end;
end;
procedure TfrmHotkeyEdit.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_F1 then
WinHelp(Handle, PChar(ChangeFileExt(Application.ExeName, '.hlp')+'>EditWnd'), HELP_CONTEXT, 3);
end;
procedure TfrmHotkeyEdit.SetControls;
var
Index : Integer;
begin
Index := cboActions.ItemIndex;
edtCommandLine.Visible := (Index=0);
edtKeysToSend.Visible := (Index=1);
cboParams.Visible := (Index=2);
lblCommandLine.Visible := Index<3;
case Index of
0 : begin
lblCommandLine.Caption := 'Co&mmandline:';
lblCommandLine.FocusControl := edtCommandLine;
end;
1 : begin
lblCommandLine.Caption := '&Keys to send:';
lblCommandLine.FocusControl := edtKeysToSend;
end;
2 : begin
lblCommandLine.Caption := 'Para&meters';
lblCommandLine.FocusControl := cboParams;
end;
end;
end;
procedure TfrmHotkeyEdit.cboActionsClick(Sender: TObject);
begin
if Item.SubItems[ITEM_ACTION] <> cboActions.Items[cboActions.ItemIndex] then
begin
Item.SubItems[ITEM_ACTION] := cboActions.Items[cboActions.ItemIndex];
case cboActions.ItemIndex of
0: Item.SubItems[ITEM_DATA] := edtCommandLine.Text;
1: Item.SubItems[ITEM_DATA] := edtKeysToSend.Text;
2: Item.SubItems[ITEM_DATA] := cboParams.Items[cboParams.ItemIndex];
else Item.SubItems[ITEM_DATA] := '';
end;
IsChanged := True;
SetControls;
end;
end;
procedure TfrmHotkeyEdit.HelpIndex;
begin
WinHelp(Handle, PChar(ChangeFileExt(Application.ExeName, '.hlp')), HELP_CONTENTS, 0);
end;
procedure TfrmHotkeyEdit.cboParamsClick(Sender: TObject);
begin
if Item.SubItems[ITEM_DATA] <> cboParams.Items[cboParams.ItemIndex] then
begin
Item.SubItems[ITEM_DATA] := cboParams.Items[cboParams.ItemIndex];
IsChanged := True;
end;
end;
procedure TfrmHotkeyEdit.edtKeysToSendChange(Sender: TObject);
begin
if (Item<>nil) and not Ignore then
begin
Item.SubItems[ITEM_DATA] := edtKeysToSend.Text;
IsChanged := True;
end;
end;
procedure TfrmHotkeyEdit.mnuHelpClick(Sender: TObject);
begin
HelpIndex;
end;
end.