我的程序需要在多文档主窗口定义多个全局热键,比如在键盘上按"+"呼出子窗口1
在键盘上按"-",呼出子窗口2,全部是单键呼出.不是组合键.
我在CSDN搜到的文档全部只能定义一个热键,而且只能在单文档中运用成功,多文档中却没有反应.

解决方案 »

  1.   

    在主窗体上放一个ApplicationEvents控件,在它的OnMessage事件中:
    procedure TMainForm.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
     if Msg.message = WM_KEYDOWN then
       case Msg.wParam of
         VK_ADD: ShowMessage('+');
         VK_SUBTRACT: ShowMessage('-');
       else
         // ShowMessage(IntToStr(Msg.wParam));
       end;
    end;
      

  2.   

    把事件都写在ApplicationEvents中的函数中
      

  3.   

    使用函数Screen.ActiveControl.Perform,下面例子是按Delete键,做Delete的工作。
    var
      State : TKeyboardState;
    begin
          GetKeyboardState(State);
          // press 'DEL' key
          if ((State[vk_Delete] and 128) <> 0) then
          begin
            if (Screen.ActiveControl.Owner is TForm) and
            begin
              DeleteSomething;  //删除工作
            end
            else
              Screen.ActiveControl.Perform(WM_KEYDOWN, VK_DELETE, 0)
          end
          else
          begin
            DeleteSomething;  //删除工作
          end;
        end
    end;加分吧!
      

  4.   

    在主窗体一个TActionList,在TActionList加一个Delete 的Action,并写上以下代码在OnExcute事件上,当按Delete键时,系统就会做做Delete的工作。
    var
      State : TKeyboardState;
    begin
          GetKeyboardState(State);
          // press 'DEL' key
          if ((State[vk_Delete] and 128) <> 0) then
          begin
            if (Screen.ActiveControl.Owner is TForm) and
            begin
              DeleteSomething;  //删除工作
            end
            else
              Screen.ActiveControl.Perform(WM_KEYDOWN, VK_DELETE, 0)
          end
          else
          begin
            DeleteSomething;  //删除工作
          end;
        end
    end;