如果说程序A是非当前状态(当前的焦点在程序B上)。现在我按Ctrl键,让程序A响应,并执行相关的操作。  现在请问以上应该怎样实现?代码应该怎样写?  谢谢!  急。~!

解决方案 »

  1.   

    首先用键盘钩子,钩住键盘,当按下了Ctrl时执行
    Application.BringToFront;
    就行了。
      

  2.   

    从B发送自定义消息到A
    A收到什么消息就做什么事
      

  3.   

    也可在A,B程序间建立通讯连接,当B程序Ctrl按下后,B程序发送相关字符给A程序,A收到后再执行相应的动作.
      

  4.   

    程序B:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
    begin
      if  Msg.CharCode = VK_CONTROL then
        SendMessage(FindWindow(nil,'Form2'), WM_APP+1, 0,0);
    end;
    end.程序A:
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        procedure WndProc(var Msg: TMessage); override;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.WndProc(var Msg: TMessage);
    begin
     with Msg do
     begin
       if Msg = WM_APP + 1 then
         Form1.Caption := 'gggggg';
     end;
     inherited;
    end;end.
      

  5.   

    当在程序B上按CTRL键时程序A的标题变为:ggggg
      

  6.   

    在这里我想告诉大家的是:B程序是Windows里面的任何一个程序,是未知的,它并不是我编的。