在画面中,如何捕获tab键。
   我用keydown来捕获,但是除了tab其他的键都能捕获

解决方案 »

  1.   

    加上这几句,再设置KeyPreview为True,就可以在OnKeyDown事件里用Key=VK_TAB来捕获了
    procedure Proc(var Msg:TWMGetDlgCode);message WM_GETDLGCODE;procedure TForm1.Proc(var Msg: TWMGetDlgCode);
    begin
      inherited;
      Msg.Result:=Msg.Result or DLGC_WANTTAB;
    end;
      

  2.   

    tab键是功能键,不会像其他按键一样会被keydown事件捕获,我通常用ApplicationEvents控件的onmessage事件判断
    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
        if (msg.wParam=vk_tab) and (msg.message=256) then
        begin
        Caption:=Caption+'a';
        Handled:=true;//想捕获后屏蔽就加上这句话,否则去掉它
        end;    
    end;