用Application中的onMessage挂接消息处理函数吧。
例子,按大写A键显示‘Hello,World!’。
*****************************************************************
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
//procedure mykeydown(var message:twmkey);message wm_keydown;
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnMessage:=appmessage;
end;
procedure tform1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if msg.message=wm_keydown then
if msg.wParam=65 then
begin
//showmessage(inttostr(msg.wparam));
showmessage('Hello,World!');
handled:=true;
end;
end;
end.