在主窗口的keydown中写下
 if (key=vk_f12) then
       form_main.N50Click(self);
不能执行。
为什么,如何做。谢谢

解决方案 »

  1.   

    先设置主窗体的KeyPreview属性为True试试;不行就看下面的例子用Application中的onMessage挂接消息处理函数
    例子,按大写A键显示‘Hello,World!’。*****************************************************************
    unit Unit1;interfaceuses
      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.
      

  2.   

    不用这么麻烦的,
    1.
    建立一个Action(用TActionList控件),将他的shortcut设置为f12,
    2.将菜单的action设为上面建立的action
    3.
    将你原来才菜单项中执行的代码拷贝到actionExcute事件中(此事件双击该action就可以生成框架