Tab key not properly forwarded to Delphi hosted WPF Visual Plugin

Hello,

There seems to be a problem with Tab key presses not being forwarded properly to Delphi hosted WPF Visual Plugins. We noticed the issue when we wanted to be able to do some custom logic in our WPF control when the user presses the Tab key. It would appear that the Tab key is being intercepted at some point prior to the WPF Visual Plugin as no events at any level in the plugin seem to be able to capture the Tab key. They do however capture all other key presses just fine.

We have attached an simple example which contains a Delphi VCL application which hosts a very simple WPF Visual Plugin. The source code for each project is included. If you run the Visual Studio test application for the Visual Plugin class library and try to tab through the DataGrid cells you should notice that the tab key is captured and a message presents this. If, however you run the Delphi application and attempt to do the same, the Tab key is not captured but if you press ‘T’ it captures the T key.

The events we have tried have been KeyDown & PreviewKeyDown at all applicable levels of visual elements in the plugin. We have also tried to override the OnPreviewKeyDown(e: System.Windows.Input.KeyEventArgs) of the VisualPlugin class but this did not capture the Tab key either.

We would appreciate it if you could show us a way to be able to capture the Tab key press in our WPF control. Thank you for your time and help.

1 Like

Hi, this happens because tab key is handled on the host (delphi) side, and we only call our internal methods to transfer focus. To workaround this problem you can override ChildSelectNextControl method to handle tab key press on the plugin side, so you will have something like this:

protected override bool ChildSelectNextControl(bool aForward)
{
  //custom tab handler here
  return base.ChildSelectNextControl(aForward);//let the plugin do its job
}

Hope this helps.

Thank you ejay, we appreciate your help. We have been able to make successful use of that override to implement our logic.

Incidentally, it would have been nice to have been able to easily find this somewhere in the documentation which would have saved raising a bug report.

Glad that you got it working.

sciclone said: Incidentally, it would have been nice to have been able to easily find this somewhere in the documentation which would have saved raising a bug report.
I've logged a task to create a separate event for this one (something like TabKeyPressed).