unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,shellapi;
type
TForm1 = class(TForm)
lbl1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
HotKeyId: Integer;
implementation
{$R *.DFM}
procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LParamHi = VK_F1) then // ALT+F1 (Msg.LparamLo = MOD_ALT) AND (Msg.LParamHi = VK_F1)
begin
//ShowMessage('F1');
if FileExists('help.chm') then
ShellExecute(handle,nil,'help.chm',nil,nil,Sw_shownormal)
else
ShowMessage('help.chm不存在');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HotKeyId := GlobalAddAtom('MyHotKey') - $C000;
RegisterHotKey(Handle, hotkeyid, 0, VK_F1); //F1
// RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F1); //ALT+F1
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle, HotKeyId); //注销HotKey
end;
end.