我想在程序中,用F5作功能键,如何截获,

解决方案 »

  1.   

    程序里有很多的组件 ,总不能每个都写吧,能不能直接截获windows的消息,如何截获,求助
      

  2.   

    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.
      

  3.   

    Msg.wParam=116 表示发生F5按键
      

  4.   

    在主窗体 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;