• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5605
  • Last Modified:

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

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
JElster
Asked:
JElster
  • 2
  • 2
1 Solution
 
venkateshwarrCommented:
Hi JElster,
you can send relevant numer of "tab" keys to go to that particular field...

Cheers!
venkat.
0
 
JElsterAuthor Commented:
Does not work...
0
 
_TAD_Commented:


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


0
 
JElsterAuthor Commented:
Any idea how ? Thanks....
0
 
_TAD_Commented:


<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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now