Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# string handling 1 27
scanning dentists xray (the small ones) 3 44
C# Single Form 8 27
C# Comparing String Arrays. 5 20
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

24 Experts available now in Live!

Get 1:1 Help Now