先聲明以下几個過程
procedure WMHotKey_f1(var Msg: TMessage);
message WM_HOTKEY;
procedure WMHotKey_f2(var Msg: TMessage);
message WM_HOTKEY;
procedure WMHotKey_f3(var Msg: TMessage);
message WM_HOTKEY;
過程實現
procedure TForm1.FormCreate(Sender: TObject);
begin
//--registry system hotkey
RegisterHotkey(form1.Handle,$DDDDA,0, VK_F1);
//VK_F10 為f10
RegisterHotkey(form1.handle,$DDDDB,0,VK_F2);
RegisterHotkey(form1.handle,$DDDDC,0,VK_F3);
end;
//相應各熱鍵的事件
procedure Tform1.WMHotKey_f1(var Msg: TMessage);
begin
if Msg.WParam=$DDDDA then
label1.caption:='f1';
end;
Procedure Tform1.Wmhotkey_f2(var msg:Tmessage);
begin
if msg.wparam=$DDDDB then
showmessage('你按了F2鍵');
end;
Procedure TForm1.Wmhotkey_f3(var msg:Tmessage);
begin
if msg.wparam=$DDDDC then
showmessage('按了F3鍵');
end;