?
Solved

Send Keys to another application without activating it

Posted on 2011-03-25
2
Medium Priority
?
950 Views
Last Modified: 2012-05-11
Hi

I am writing a WPF application using VB .NET and am trying to find sample code for sending (if possible) keystrokes (sometimes single characters, sometimes whole strings and sometimes control keystrokes such as ENTER) to another application.

We have a legacy application that does not expose an API for automation/interop and as such until we redevelop, have to hack it by sending keystrokes.  However, we would prefer to avoid using AppActivate seeing that we cannot guarantee the popping up of the application at random intervals will not cause other issues when someone is using the computer.

So in short, is it possible to send (complex) keystrokes to another application without activating it using VB .NET and if so, how?

Thanks
Vyyk
0
Comment
Question by:Vyyk_Drago
[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 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35215804
Yes...but you have to use windows APIs to achieve it.

Basically you need a handle to the window you want to send to (like a TextBox).  Then you use SendMessage() to either simulate individual keystrokes or to set the text outright.  We can't tell you the exact correct combination as every application is different and may need one approach or another to make it "behave" correctly.  Invoking menus gets a little tricky as well as the window that processes those types of messages sometimes is not even visible and isn't obvious.

Tools such as Spy++ can be very useful in figuring out the window hierarchy and structure of the external app.

To get the main window handle you can use something like Process.GetProcessesByName().

To get child windows you can use these APIs alone, or in combination:
EnumWindows(), EnumChildWindows()
FindWindow(), FindWindowEx()
GetWindow(), GetNextWindow()

To inject the info use SendMessage().

Look these up on the MSDN website for more info and then do a web search.
0
 

Author Closing Comment

by:Vyyk_Drago
ID: 35240600
Thanks, very helpful.
0

Featured Post

Independent Software Vendors: 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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