Solved

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

Posted on 2011-03-16
5
2,570 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now