procedure TForm4.FormCreate(Sender: TObject);
begin
SetKey; //注册热键
end;
procedure TForm4.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle, HotKeyID);
DeleteAtom(HotKeyID);
end;
procedure TForm4.HotKeyDown(var Msg: TWMHotKey);
begin
if (Msg.HotKey = HotKeyID) then
begin
//
end;
end;
procedure TForm4.SetKey();
var
Sc: TShortCut;
Modifiers, vk: Word;
Shift: TShiftState;
Str: string;
begin
{注册热键}
HotKeyID := GlobalAddAtom('HotKeyID') - $C000;
with TIniFile.Create('Config.ini') do
begin
Modifiers := 0;
vk := 0;
Str := ReadString('Config', 'CustomKey', 'Ctrl+F11');
if Str = '' then
Str := 'Ctrl+F11';
Sc := TextToShortCut(Str);
ShortCutToKey(Sc, vk, Shift);
if ssShift in Shift then
Modifiers := Modifiers or MOD_SHIFT;
if ssCtrl in Shift then
Modifiers := Modifiers or MOD_CONTROL;
if ssAlt in Shift then
Modifiers := Modifiers or MOD_ALT;
Free;
end;
UnregisterHotKey(Handle, HotKeyID);
RegisterHotKey(Handle, HotKeyID, Modifiers, vk);
end;
procedure TForm4.CmdSetClick(Sender: TObject);
var F: TFrmSet;===> 这行报错了,我用CnPack的单元引入工具时,出来长长的ListBox选择这么多,我哪知是哪一个呢? 有什么技巧吗?
我不认识它,它更不认识我
Ini: TIniFile;
BB: Boolean;
begin
F := TFrmSet.Create(self);
Ini := TIniFile.Create('Config.ini');
try
with F do
begin
//读到INI热键参数到 hotkey 控件中
HotKey.Hint := Ini.ReadString('Config', 'CustomKey', 'Ctrl+F11');
if HotKey.Hint = '' then
HotKey.Hint := 'Ctrl+F11';
HotKey.HotKey := TextToShortCut(HotKey.Hint);
HotKey.Hint := '';
if ShowModal = mrok then
begin
Ini.WriteString('Config', 'CustomKey', ShortCutToText(HotKey.HotKey)); //写入新的热键设置
SetKey; //生效新的热键
end;
end;
finally
Ini.Free;
F.Free;
end;
end;