Question

I would like to use SendKeys.SendWait("keys") to send some keystrokes to a minimized or non-visible application.

Experimentally, it only appears to work when the application I'm sending it to has the focus and is visible. I tried giving the application the focus when it was not visible, to no avail. I'm hoping I've missed something. Is there any way to do this?

Background:

I"m trying to force a 3rd-party install package that does not support silent installation to be as quiet and automated as possible. I contacted the folks who created installer, and they didn't enable silent installs and won't be releasing a new one.

The installer is an InstallAnywhere package that spins up Java AWT. Because of this, Spy++ won't show me IDs for buttons. The only thing I get is the handle for the main window, which leads me to believe I have to send keys using SendKeys.SendWait("keys") to get the automation I need.

I can get it to walk through the installation using SendKeys.SendWait("%n") (for "Alt-N" making it press the "Next" button), but I want to hide the window. Because I can't tell when it's done with a particular stage, I'm polling it periodically, and pressing the appropriate key. It's a huge hack, but I haven't found a better option. The problem is, I don't want to minimize then restore for each of these keypresses. There's got to be a better way than this, right?

Using C# .NET 4.0 on Windows 7.

Was it helpful?

Solution

Unfortunately keyboard input goes to the active window, so anything that simulates keyboard input will behave the same way.

If they added Accessibility hooks, then you can use the UI automation framework. Here is a quick sample from Raymond's blog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top