请问怎么捕获Tab键按下这个事件?请先测试一个再告诉我好吗?

解决方案 »

  1.   

    onKeyPress事件,检查Key值,tab键的ASCII码为#9,
    这还需要测试吗?
      

  2.   

    怎么会没有用,肯定是你的form上的keypreview属性为false,
    只要设置keypreview属性为true,然后你就可以在onKeyPress事件检查Key值了
      

  3.   

    procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key = $9 then
        ShowMessage('TAB key pressed!');
    end;这样很好啊。
      

  4.   

    “怎么会没有用,肯定是你的form上的keypreview属性为false,
    只要设置keypreview属性为true,然后你就可以在onKeyPress事件检查Key值了”
    请你先试一下再说吧,不信你写段代码试试
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }    procedure gettab(var msg:Tmessage);message WM_KEYUP;
      end;
    var
      Form1: TForm1;implementation{$R *.dfm}
      procedure TForm1.gettab(var msg:Tmessage);
      begin
       if integer(msg.WParam) = VK_TAB then showmessage('tab get');
      end;
    end.
    搞定!
      

  6.   

    不好意思刚才没看清,好象确实如斑竹所说的一样,
    下面的肯定行
    function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
    var
       s:string;
    begin
      if (PEventMsg(lparam)^.message = WM_KEYDOWN) then
      begin  if  peventMsg(lparam)^.paramL =3849 then   //tab键的扫描码
      begin
         //showmessage('get')//在xp下,总是不断弹出,最后异常,可能是因为弹出新窗体,//局部钩子就无效了吧。不过肯定是捕获到了tab
      end;
      end ;end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
    end;
      

  7.   

    if key = vk_tab then
    begin
        .
        .
        .
    end;
      

  8.   

    procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key = 9 then
        ShowMessage('TAB!');
    end;
      

  9.   

    一定要用     OnKeyUp