Solved

C# SendKeys -  Need to use SendKeys or any other method to set 'focus' to another application.

Posted on 2004-04-12
5
5,580 Views
Last Modified: 2012-06-27
I have C# App. that launches another program. I need to write code that will set focus to the other application and do a paste. I have the code to paste.
Can not figure out how to set focus to the other app. Even if the other app. the top most app. The Send Keys does not work. Can I do a SendKeys Mouse Click?
TIA
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10805405
Hi JElster,
you can send relevant numer of "tab" keys to go to that particular field...

Cheers!
venkat.
0
 
LVL 1

Author Comment

by:JElster
ID: 10805477
Does not work...
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10805692


You'll need to use WinAPI to find the proper window and set the focus manually.


0
 
LVL 1

Author Comment

by:JElster
ID: 10805717
Any idea how ? Thanks....
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 100 total points
ID: 10805723


<Call DLL>

[DllImport("User32",EntryPoint="SetForegroundWindow")]
private static extern bool SetForegroundWindow(System.IntPtr hWnd);



<Execute Function   -   Button Click Event>

if(prc.Responding)
{
     SetForegroundWindow(prc.MainWindowHandle);
     SendKeys.SendWait("_TAD_");
     SetForegroundWindow(this.Handle);
}




The process "prc" is a notpad process that I opened.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

696 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