I need to type something in a textbox inside a web-browser control. Simply setting the value doesn’t work because this doesn’t run javascript.
So:
-
InvokeMember: I thought I could use invokemember for this(since there’s
InvokeMember("Click")). But google is silent about keyboard events. -
Focus the element and then send keys to the control. It works(
Sendkeys.Send), but only if the control is activated. If I switch to another window, it will send keys completely, but not where I want to. - Javaspript: Is there a way to find out which javascript runs when I change the value of a textbox? I don’t know much about javascript. Elements attributes don’t have something like OnClick/OnKeyUp etc.
So… In case anybody is interested.
What is possible? Its possible to send keys to a window… Teoretically its possible to send keys to unactive window(using SendMessage() and PostMessage()), but practically nobody has successfully done this since WinXP & x32 times…
I didnt try myself, but there are people who was able to send keys using “SendInput”. But this useless anyway, cause the function can only send keys to active window.
So… SendKeys.Send(which, i guess, is a wrapper for SendInput) is still the best way around.
Solution
I created a form(window) for my webbrowser control. I initialize it, but dont use “Show”. Then i simply make this form active right before “SendKeys.Send”(dont forget to focus on both element(inside the control) and control(inside the form) as well). Since there is no form to show, user doesnt notice anything and keys go to the right window. If its needed, its possible to save the handle of window which was active previously and make it active again after the sending(so focus wont be lost).
Summary
Although im ok with this solution and i will use it, its far from perfect… If anybody finds something better, please let me know(even in distant future).