Solved

Send Keys to another application without activating it

Posted on 2011-03-25
2
930 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
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

23 Experts available now in Live!

Get 1:1 Help Now