Solved

Send Keys to another application without activating it

Posted on 2011-03-25
2
945 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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