unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; procedure FormCreate(Sender: TObject); private { Private declarations } procedure onMessage(var Msg: TMsg; var Handled: Boolean); public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage:=onMessage; end;procedure TForm1.onMessage(var Msg: TMsg; var Handled: Boolean); begin if Msg.message =WM_KeyDown then begin edit1.Text :=''; if Msg.wParam=116 then begin edit1.Text :='I Find!'; //其它处理 Handled:=true; end; end; end;end.
Msg.wParam=116 表示发生F5按键
在主窗体 OnCreate 中写 Application.OnMessage := OnMyMessage;procedure TForm1.OnMyMessage(var Msg:TMsg;var Handled:Boolean); begin if Msg.message = WM_KEYDOWN then if Msg.Wparam = VK_F5 then begin ShowMessage('你按下的是F5键'); Handled := true;(系统不处理F5键) Handled := false;(默认为False,系统还有处理F5键) end;end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure onMessage(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=onMessage;
end;procedure TForm1.onMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message =WM_KeyDown then
begin
edit1.Text :='';
if Msg.wParam=116 then
begin
edit1.Text :='I Find!';
//其它处理
Handled:=true;
end;
end;
end;end.
begin
if Msg.message = WM_KEYDOWN then
if Msg.Wparam = VK_F5 then
begin
ShowMessage('你按下的是F5键');
Handled := true;(系统不处理F5键)
Handled := false;(默认为False,系统还有处理F5键)
end;end;