Results 1 to 5 of 5

Thread: sendkeys - i need help!!!!!!!!1

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    derbyshire
    Posts
    9

    Exclamation

    I want to try to send some keys to a program and then get a return of any text that is there for example in word. can anyone help me? please help me

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You should use SendMessage for both

    I wrote a quick example for use with notepad, fire it up and test the code
    Code:
    Option Explicit
    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 Integer, ByVal lParam As Any) As Long
    Private Const WM_GETTEXTLENGTH = &HE
    Private Const WM_GETTEXT = &HD
    Private Const WM_SETTEXT = &HC
    
    Private Sub Form_Load()
    Dim lNoteP&, edit&
    lNoteP = FindWindow("Notepad", vbNullString)
    edit = FindWindowEx(lNoteP, 0&, "Edit", "")
    
    MsgBox GetText(edit)
        SetText edit, "HEYYY IK BEN JOP"
    MsgBox GetText(edit)
    End Sub
    Private Sub SetText(Wnd As Long, Text As String)
        SendMessage Wnd, WM_SETTEXT, ByVal CLng(0), ByVal Text
    End Sub
    Private Function GetText(Wnd As Long)
    Dim l%, Wintext$, retval&
        l = SendMessage(Wnd, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
        Wintext = Space(l)
        retval = SendMessage(Wnd, WM_GETTEXT, ByVal l, ByVal Wintext)
    GetText = Left(Wintext, retval)
    End Function
    Jop - validweb.nl

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

  3. #3
    Guest
    You don't need the declaration of FindWindow and FindWindowEx. Just use FindWindowEx for both.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    derbyshire
    Posts
    9

    thanx

    Thanx for the help. it works fine

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    derbyshire
    Posts
    9

    Question can you help me jop

    i ot your e-mail and i dont mind if it takes you a while to reply. thanx for the help

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