I have a WebBrowser
control shown in a custom task pane in an Microsoft Office Application-level add-in created in Visual Studio. The web page shown in the WebBrowser
doesn't receive keyboard events that can be handled by JavaScript code, such as KeyUp
. The same page shown in a comparable WebBrowser
in a Form
does receive keyboard events. The WebBrowser
control itself doesn't seem to expose any events related to keyboard input, and I don't seem to be able to handle keyboard events by adding event handlers to the UserControl
added as a custom task pane.
I have created a minimal example – a Visual Studio solution – which recreates the problem.
Is there any way to pass on keyboard events to the web page?
Yup, you can do it. You'll have to hook into the HTML DOM events (like onclick, onmouseover, etc.). Take a look here: http://www.w3schools.com/jsref/dom_obj_event.asp.
And there's an example here: http://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values
I think you'll have to add a reference to the MSHTML library. BTW, put the WebBrowser control in a Panel control or it will act goofy - especially with keyboard events.