Solved

c#- SendKeys.Send("{tab}") to Internet explorer

Posted on 2011-03-16
5
2,648 Views
Last Modified: 2012-05-11
HI,

I have created a simple winform application to launch the browser on a click of the button. The code is as follows:

        private void button1_Click(object sender, EventArgs e)
        {
           Process IEProc = new Process();
           IEProc.StartInfo.FileName = "iexplore.exe";
           IEProc.StartInfo.Arguments = "http://google.com";
           IEProc.Start();
           //IEProc.StandardInput.Write("Hello World");
           
           SendKeys.Send("{tab}");
        }

The purpose of putting the line "SendKeys.Send("{tab}");" is to navigate to the new field on google.com. However, the tabbing is happening on winform application. Can someone please let me know how the tab can be used on google.com.

Appreciate your help.


0
Comment
Question by:deoyagya
5 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 35145921
When opening the iexplore you should just wait for a few moments before sending the TAB.
Why?

the iexplore is still opening when the TAB is send, and your winform is still in front. ;-)

waiting :
using System.Threading;


Thread.Sleep(10 * 1000); // 10 Seconds delay


regards

poor beggar
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35145928
try this

      IEProc.Start();
                  IEProc.WaitForInputIdle();

                  SendKeys.Send("{tab}");
0
 
LVL 4

Accepted Solution

by:
parnasso earned 300 total points
ID: 35146016
In order to implement the SendKeys function, you need to finde the internet explorer window that receives the user input and send an WM_KEY... message to it. I'm not sure if your approach is going to give you more problems than you think.

I would suggest to add a reference to the internet explorer interface through COM (automation). If you are not familiar with automation, take a look at this project:

Internet explorer automation
0
 
LVL 12

Assisted Solution

by:FarWest
FarWest earned 200 total points
ID: 35146512
you can get the process window handle, and the setfoucs to that window, before sending keys
check this, http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx


and pay attention to this note in the page
"If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, an exception will be thrown."


good luck
0
 

Author Closing Comment

by:deoyagya
ID: 35275429
Thanks for the assistance.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question