|
-
Sep 17th, 2009, 10:13 AM
#1
Thread Starter
Member
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!
-
Sep 17th, 2009, 10:23 AM
#2
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.
-
Sep 17th, 2009, 10:24 AM
#3
Hyperactive Member
Re: SendKeys to a specific Windows Handle
I'm pretty sure you can use the SendMessage/PostMessage API to do so.
-
Sep 17th, 2009, 10:44 AM
#4
Thread Starter
Member
Re: SendKeys to a specific Windows Handle
Something like...?
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.
-
Sep 17th, 2009, 10:57 AM
#5
Hyperactive Member
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/
-
Sep 17th, 2009, 11:49 AM
#6
Thread Starter
Member
Re: SendKeys to a specific Windows Handle
-
Sep 18th, 2009, 11:25 AM
#7
Thread Starter
Member
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?
-
Sep 22nd, 2009, 05:47 AM
#8
Thread Starter
Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|