mardi 21 avril 2015

.Net Embedded WebBrowser control is not recognizing tab and arrow key

I have a created a WinForms custom control inheriting from the WebBrowser control. I have put an ActiveX wrapper around that control so we can use in other third party applications.

When the browser control renders a page the tab and arrow keys do not work, i.e., I cannot tab from element to element on the page. If I dock the control in a managed code application it works fine (non-ActiveX mode). But as soon as I drop on a third party app (created using Delphi 7) instantiated as ActiveX control the issue surfaces.

I can install a hook (WH_GETKEYBOARD) and can see the tab keystroke while in the control but have not yet been able to forward the strokes on to the actual browser. I am missing something here but not sure what.

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
[Guid("E82A8888-9999-4444-3333-888888888141")]
[ProgId("MYTEST.BrowserControl")]    
[ClassInterface(ClassInterfaceType.AutoDispatch), ComSourceInterfaces(typeof(ITestComCallableEvents))]
public partial class TestBrowserControl : WebBrowser, ITestComCallableMethods
{
    public TestBrowserControl()
    {
        InitializeComponent();
        //KeyStrokeHook is class implementing low level hooks using windows API
        mksh = new KeyStrokeHook(HookType.WH_KEYBOARD);
        mksh.HookInvoked += new KeyStrokeHook.HookEventHandler(MyHook);
        //install the hook
        mksh.Install();
     }

     void MyHook(object sender, HookEventArgs e)
     {
        IntPtr wParam = e.wParam;
        IntPtr lParam = e.lParam;
        //catch tab key
        if (wParam == (IntPtr)0x09)
        {
           //do something here to forward tab key to browser control
        }
     }
  }

Aucun commentaire:

Enregistrer un commentaire