Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindWindow,SetActiveWindow, then Sendkeys

Status
Not open for further replies.

MattSTech

Programmer
Apr 10, 2003
333
US
Hello All,
I am attempting to find a window, give it focus, then sendkeys to it in VB6.

Found window by using FindWindow API
Gave it focus using SetActiveWindow API

Problem:
after the SetActiveWindow call the window doesn't accept the keys sent, it actually seems as if the window waits until all keys have been sent before it gives the window focus.

Thanks

Matt

Code:

Private Sub cmdAttAy_Click()
Dim a as long

a=FindWindow(vbNullString, "Attay Toolbar")
SetActiveWindow a
SendKeys "{F5}"

End Sub
 
Probably you are having a temporization issue here (but I'm not a Basic programmer, so I'm guessing).

1) Insert some delay between SetActiveWindow and SendKeys, to be sure the OS have the time to process the focus message

or

2) Post the key in a WM_KEYDOWN message (you have the handle, so it is not difficult).

HTH.
buho (A).
 
I have tried a Wait command but the window just waits until the Wait delay has passed then sets focus. Meaning if I set the delay at 10 seconds, it will wait 10 seconds before setting focus to the window even though the wait is placed after the SetActiveWindow statement. As for your second suggestion, are you suggesting a SendMessage call should be used as opposed to a sendkeys?
Thanks for the quick response

Matt
 
I will attempt to find that answer in the VB6 Forum, thanks again for the help.

Matt
 
Yes, you can use SendMessage. In this particular situation (you are talking to a foreign window) PostMessage is better.

buho (A).

 
Take a look at thread222-830490 I ave just done the same thing, might help you.

Greg Palmer

---------------------------------------Free Software for Adminstrators
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top