Is there any way for a control to know that it was tabbed out of?

My solutions below fails. It works okay for tabbing forward, but when
tabbing backward, focus goes into la-la land.

I do detect TAB, but then windows wants me to dealw ith it, and that fails.

I think there must be a different approach.

Cheers

// signal we want to know about the TAB key
procedure TMyControl.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  inherited;
  Message.Result:=Message.Result OR DLGC_WANTTAB;
end;


// Set propety TabbedOut if that is how we lose focus
// SAdly, we must now also handle the tab key
procedure TMyControl.WndProc(var Message: TMessage);
begin
  case Message.Msg of

    WM_SETFOCUS:
      begin
        TabbedOut:=False;
      end;

    WM_KEYUP:
      begin
        if TWMKey(Message).CharCode = VK_SHIFT then
        begin
          FKeyShift := False;
        end;
      end;

    WM_KEYDOWN:
      begin
        if TWMKey(Message).CharCode = VK_SHIFT then
        begin
          FKeyShift := True;
        end;

        // Yes, we have a TAB
        TabbedOut := TWMKey(Message).CharCode = VK_TAB;

        if TabbedOut then
           SendMessage(FParentForm.Handle,WM_NEXTDLGCTL,0,
Integer(FShiftKey) );

      end;
  end;
  inherited wndProc(Message);
end;


Reply via email to