Link to home
Start Free TrialLog in
Avatar of born4code
born4code

asked on

"send keys" to another app from vb.net?

Does anyone know an easy way to send keys to another window from vb.net?

For example, let's say that I programmatically open application X from vb.net.  Application X has a popup box that asks for a password.  I want to automatically insert the password into that popup box from vb.net.

Thanks.
Avatar of wguerram
wguerram

In The MSDN:

Dim ReturnValue, I
ReturnValue = Shell("calc.exe", 1)   ' Run Calculator.
AppActivate ReturnValue    ' Activate the Calculator.
For I = 1 To 100   ' Set up counting loop.
   SendKeys I & "{+}", True   ' Send keystrokes to Calculator
Next I   ' to add each value of I.
SendKeys "=", True   ' Get grand total.
SendKeys "%{F4}", True   ' Send ALT+F4 to close Calculator.

Keys are processed by active application
Take a look at this:

This find a window and activates, the close the form

http://www.mentalis.org/apilist/FindWindow.shtml
ASKER CERTIFIED SOLUTION
Avatar of Daniellus83
Daniellus83
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of born4code

ASKER

Whew!
Okay guys... I'm in a hotel w/laptop... let me try this out and I'll get back to you...

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've tried the sendkeys method... actually it appears that I have user SendKeys.Send in .net

Unfortunately, while it works great in something like the windows calculator, it is ignored by some applications.  Not really sure why.  One of the first keys I want to send is just the UP arrow, i.e., SendKeys("{UP}"), but the application just ignores it.  I'm almost wondering if the splash screen of the application still has the focus when the application starts up, and therefore it cannot receive the keys because it does not have focus.  Perhaps if there was a way to "stall" for a few seconds before I sent the keys it would work.

thoughts?
Like I said - it is not actually ignored.

Just that the right control is not in focus.

Gajendra
ok.
So, let's say that I fire up an application with a shell command... the application shows up immediatly, takes place as the first window on the pc.  So then one of these below must apply.... which one do you think it is?

Perhaps...

1) It does not have focus, even though it was just called and exists as the first window.  This is because...

2) It does have focus, but the keys are being ignored because...

3) The splash screen of the application has focus first, so the sendkeys code is being intercepted by the splash screen.  A way to get around this would be to...

Thanks.
Try this

'"Personal Folders Password" is the name of my oulook password window.

AppActivate("Personal Folders Password")        'This activates the window which is waiting for a password to be inputed
SendKeys.SendWait("MyPassword{ENTER}")    'Then the password is written
I mean by name, the caption title of the window.

"Personal Folders Password"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All guys wrote comments and provide links on a common task and all of then received points but not me.

All of them gave you the same comments as mine.

Now the question is, why didn't i received points on this?