请问如何判断按下了 Tab 键和 Shift 键

解决方案 »

  1.   

    OnKeyDown事件中if ((Shift = ssShift) and (Key = VK_TAB)) then
     ...
      

  2.   

    unit TrappingTabs;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Grids;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        procedure FormKeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
      private
        { Private declarations }
        procedure WMGetDlgCode(var msgIn: TWMGetDlgCode); message WM_GETDLGCODE;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.WMGetDlgCode;
    begin
       inherited;
       msgIn.Result := msgIn.Result or DLGC_WANTTAB;
    end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key = VK_TAB then
         ShowMessage('Tab');
    end;end.