-
I was wondering how to use SendKeys to send text to AOL Instant Messager. I have the text I want to send in a text box, but when I try to send the message, nothing happens. I think it is because there are two textboxes in instant messager, and the first one is read-only. Would this question fit better in the API section of the forums?
Joey (MidgetsBro)
-
Maybe you need the Hwnd to that paticular textbox ? Just a thought .
-
hehe good thinking :)
I don't have AOL messenger so I can't test it, but you need to find the handle of the textbox with an API spy, then use
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub AOL()
Dim a&, t&, t2&
a = FindWindow("CLASSNAME", "CAPTION")
t = FindWindowEx(a, Byval 0&, "CLASSOFTEXTBOX", "")
'if there's another textbox with the same class and the first one doesn't work use:
't2 = FindWindowEx(a, t, "CLASSOFTEXTBOX", "")
'then set the text using
SendMessage t, WM_SETTEXT, ByVal CLng(0), ByVal "MYNEWTEXT"
'or if you use the second textbox
SendMessage t2, WM_SETTEXT, ByVal CLng(0), ByVal "MYNEWTEXT"
End Sub
have fun!
-
Can I use Spy++ to get the textbox class name? I have the window class name, but I can't find the textbox one. If anyone has made a program that sends text to an Instant Message window, please respond. BTW thanks Jop, that code should work once I get the textbox name.
-
Yup, just move your mouse over the textbox and it should work.
Anyway, if that doesn't work download Kedaman's Class Explorer from his homepage (www.kedaman.com)
-
aim 4p1
i tried helping someone send text to a chat window in aim and i'm guessing this should be about the same if ur still planning to use the sendkeys
the way you have to do it is by find the title of the IM
appactivate "the screenname - instant message"
once you activate it you have to find out where the focus is given to the IM ...
to send a message to the chat i had to send the TAB key seven times so the cursor would position in the textbox
so see how many times you have to press tab
finally the code would look like:
appactivate "the screenname - instant message"
for x = 1 to 4
sendkeys {vbtab}
next x
sendkeys thetextboxname.text
hopefully that works
-
Thanks man! That worked really well. I was researching Jop's code and trying to find all that info about the IM box, and I got the e-mail about your code. I tried it and it works. The only thing is that the Instant Message window has to be open. Oh well that's a small price to pay for somthing this good. Thanks again.