SendKeys to a specific Windows Handle
Hey,
Is it possible to send keys to a specific windows handle without having to bring that window to focus?
Right now I have the following code almost doing the trick:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Integer
Sub SendKeysToApplication(ByVal AppTitle As String, ByVal Keys As String)
Dim hWnd As Long = FindWindow(Nothing, AppTitle)
If hWnd <= 0 Then
'*** TO DO *** Window doesn't exist exception
End If
SetForegroundWindow(hWnd)
SendKeys.SendWait(Keys)
End Sub
Upon calling it as
Code:
SendKeysToApplication("Calculator", "{1}")
It will bring the windows calculator window to the top and set the value "1" on it.
My question is: Is it possible to send the keystroke without poping the window?
Thanks!
Re: SendKeys to a specific Windows Handle
SendKeys requires the window to have focus. You might be able to use the SendMessage or PostMessage Win32 APIs to achieve this.
Re: SendKeys to a specific Windows Handle
I'm pretty sure you can use the SendMessage/PostMessage API to do so.
Re: SendKeys to a specific Windows Handle
Something like...?
Quote:
Sub SendMessageToApplication(ByVal AppTitle As String, ByVal Msg As String)
Dim hWnd As Long = FindWindow(Nothing, AppTitle)
SendMessage(hWnd, Msg, Nothing, Nothing)
End Sub
This is resulting in an "Arithmetic operation resulted in an overflow." upon calling the SendMessage command though.
Re: SendKeys to a specific Windows Handle
Check out this article for some information on the parameter types and how you use them:
http://www.developerfusion.com/artic...message-api/3/
Re: SendKeys to a specific Windows Handle
Re: SendKeys to a specific Windows Handle
I'm back... \o/
I've read through that documentation but I'm still stuck.
For instance, if I want to tell another process to do Alt -> E -> H -> F (which will trigger a menu option on this other process) without bringing any of it's forms to top, what's the way to go?
Re: SendKeys to a specific Windows Handle
Alright so,
I'm getting my way around SendMessage although finding object handles is proofing to be a major pain in the butt, specially for random toolbar buttons with no associated label whatsoever.
My question is: Is it possible to provide input to a window's current focus with SendMessage? As in, I know that at a given time, a textbox will be focused on that specific form; Can I directly input on it without having to go dig around it's handle?
Thanks!