问题是我没有用过hook,  还要花点时间去看看有关的程序
   

解决方案 »

  1.   

    有很经典的例子!需要可以mail给你!
      

  2.   

    谢谢  我的mail :  [email protected]
      

  3.   

    [email protected] 谢谢!:)
      

  4.   

    很简单:
    {先设Form1.KeyPreview:= ture}
    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (ssCtrl in Shift) and (Key = VK_TAB) then ShowMessage('CTRL_TAB');
    end;
      

  5.   

    不知道registerhotkey能不能行
    以前看过一个处理这个的例子,可惜找不到了:(
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private    { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
      hHook: integer;
      ctrl:boolean;
    implementation
    {$R *.DFM}function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
    begin
      if (peventmsg(lparam)^.message = WM_KEYDOWN) then
      begin
         if ( (ctrl) and (peventMsg(lparam)^.paramL= 3849{//tab})) then    Form1.ListBox1.Items.Add('ok!');
         if peventMsg(lparam)^.paramL=7441 {//ctrl}    then ctrl:=true else ctrl:=false;
      end;end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      hHook := 0;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      UnHookWindowsHookEx(hHook);
      hHook := 0;
    end;end.
      

  7.   

    直接用applicationevents不好么?
    当ctrl keydown发出以后,让某个全局变两=true,表示ctrl 按下,keyup发出以后,=false,
    在这期间检测tab的keydown和keyup消息。
    ctrl:17
    tab:9
    这种方法比较朴素,嘻嘻:)
      

  8.   

    但是只能捕捉本窗口active时的message
      

  9.   

    还是用superyiman(役满)兄弟的hook方法吧。
    我也学习学习
      

  10.   

    但是问题又来了,
       我希望是Ctrl不松手,连续的按tab, 以上程序必须是完全的松开tab+ctrl ,让后同时的按下, 才能触发
      

  11.   

    自己把 HookProc中的逻辑改一下不就行了
      

  12.   

    var
      Form1: TForm1;
      hHook: integer;
      lastkeydown:string;
      ctrlup:boolean;function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
    var
    key:string;
    begin
      if (peventmsg(lparam)^.message = WM_KEYDOWN) then
      begin
          if peventMsg(lparam)^.paramL= 3849 then  key:='tab';
          if peventMsg(lparam)^.paramL=7441  then
          begin
            key:='ctrl';
            ctrlup:=false;
          end;
          if (((lastkeydown= 'ctrl')or (not ctrlup)) and  (key='tab')) then
          begin
            Form1.ListBox1.Items.Add('ok!');
          end;
          lastkeydown:=key;
      end;
      if (peventmsg(lparam)^.message = WM_KEYUP) then
      begin
          if peventMsg(lparam)^.paramL=7441  then  ctrlup:=true;
      end;
    end;
      

  13.   

    如果要用hook,应该写到dll里面去,才能全局hook!