I have a System.Windows.Forms webbrowser control that is not firing the keydown events.
Here is the code: the mouse down event fires, but the keydown event does not. Are there any criteria for the keydown event triggering?
IWebBrowser2 browser;
mshtml.HTMLDocument doc;
mshtml.HTMLDocumentEvents2_Event iEvent;
browser = (IWebBrowser2)_browser.ActiveXInstance;
if (browser == null)
return;
doc = (HTMLDocument)browser.Document;
if (doc == null)
return;
iEvent = (HTMLDocumentEvents2_Event)doc;
if (iEvent != null)
{
iEvent.onkeydown += new mshtml.HTMLDocumentEvents2_onkeydownEventHandler(keyDown);
iEvent.onmousedown += new HTMLDocumentEvents2_onmousedownEventHandler(iEvent_onmousedown);
}
}
Try using
PreviewKeyDownevent instead ofKeyDown. SincePreviewKeyDownfires beforeKeyDownevent.Check this link for more information on how to bind this event.
Hope this helps