Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am making a desktop app with browser, which posts comment

the Enter button is required to be pressed to post the comment

right now i am using folowing code

C#
txt = "how r u";
            string initial = "";
            HtmlDocument Document = (HtmlDocument)e.Argument;
            foreach (HtmlElement hform in Document.GetElementsByTagName("form"))
            {
                if (hform.GetAttribute("action") == "/ajax/ufi/modify.php")
                {
                    foreach (HtmlElement hbtnComment in hform.GetElementsByTagName("input"))
                    {
                        if (hbtnComment.GetAttribute("value") == "Comment")
                        {
                            hbtnComment.InvokeMember("click");
                            System.Threading.Thread.Sleep(1000);
                            Application.DoEvents();
                            break;
                        }
                    }

                    HtmlElement htxtArea = hform.GetElementsByTagName("textarea")[0];
                    initial = htxtArea.InnerText;
                    htxtArea.Focus();
                    System.Threading.Thread.Sleep(200);
                    Application.DoEvents();
                    htxtArea.InnerHtml = txt;// +"<input id=\"abc\" type=\"submit\">";
                    System.Threading.Thread.Sleep(200);
                    Application.DoEvents();
                    SendKeys.SendWait("{ENTER}");
                    System.Threading.Thread.Sleep(200);
                    Application.DoEvents();
}
}


the problem with this code is, that it using SendKeys function, which requires the application to remain in focus, if the application is minimized then this code doesnt work

so kindly anyone who can help me in telling how we can make the text area feel that Enter key has been pressed
Posted

1 solution

Have a look at this tutorial http://www.vivid-abstractions.net/programming/tutorials/video-tutorial-send-keys-to-an-inactive-window-windows-messages/[^]
If that doesn't give you enough detail then google for sendkeys inactive application and have a look at the other suggestions.

Here[^] is a list of the Windows Message codes and here[^] is the official blurb,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900