Solved

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

Posted on 2004-04-12
5
5,574 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 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