Search code examples
c#browsersendkeyspostmessage

Is it possible to sendkeys / Post Message directly to a HtmlElement rather than to a webbrowser control?


I would like to send keys to a c# web browser control element directly, not just the window with the correct focus.

Right now I am able to send a key using PostMessage and documentHandle and focus like this

i.e. Pseudo Code

HtmlElement el = getelement();
el.Focus();
IntPtr docptr = browser.Handle;
PostMessage(docptr,WM_KEYDOWN,1,0);
.... KEYCHAR, KEYUP..

I was wondering if anyone knows of any way to be able to do this in a background, so that the focus is not on the element. Basically is there a way to get a IntPtr to the HtmlElement itself, than use that instead in the PostMessage or SendKeys API rather than the browser handle/ptr.


Solution

  • You can't. Those are windowless controls, mouse/keyboard messages are handled by their parent window, and the parent only relay message for the active control.