Results 1 to 7 of 7

Thread: sending text to Instant Messager

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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)
    <removed by admin>

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Maybe you need the Hwnd to that paticular textbox ? Just a thought .
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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!

    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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.
    <removed by admin>

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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)
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305

    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





  7. #7

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    Cool

    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.
    <removed by admin>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width