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

Send Keys to another application without activating it

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
Vyyk_Drago
Asked:
Vyyk_Drago
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Vyyk_DragoAuthor Commented:
Thanks, very helpful.
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.

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