Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

SendKeys Method

Hi all, hope someone can help me or clear it up for me. Currently Im trying to do send keys to notepad. It works completely but I need Notepad to have the focus. Is there any way to get sendkeys to work without focus so I could have my program sending keys to notepad while I browse the net??

Comments

  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : Hi all, hope someone can help me or clear it up for me. Currently Im trying to do send keys to notepad. It works completely but I need Notepad to have the focus. Is there any way to get sendkeys to work without focus so I could have my program sending keys to notepad while I browse the net??
    :

    Using SendKeys, no. You can try using SendMessage with the WM_KEYDOWN/WM_KEYUP messages. You'll need to get the textbox's handle to do this. I've never used it, but you can EnumWindows to find the window. With notepad, it's fairly simple because it's the only editbox on the form. Either EnumWindows will tell you the type of window or you can use GetWindowClass on every window contained in the notepad window (ID'able by a caption Like "Notepad - *") until you find one whose class is (I think) "edit".

    Hope this helps,
    KDL
  • CGuy35CGuy35 Member Posts: 29
    : : Hi all, hope someone can help me or clear it up for me. Currently Im trying to do send keys to notepad. It works completely but I need Notepad to have the focus. Is there any way to get sendkeys to work without focus so I could have my program sending keys to notepad while I browse the net??
    : :
    :
    : Using SendKeys, no. You can try using SendMessage with the WM_KEYDOWN/WM_KEYUP messages. You'll need to get the textbox's handle to do this. I've never used it, but you can EnumWindows to find the window. With notepad, it's fairly simple because it's the only editbox on the form. Either EnumWindows will tell you the type of window or you can use GetWindowClass on every window contained in the notepad window (ID'able by a caption Like "Notepad - *") until you find one whose class is (I think) "edit".
    :
    : Hope this helps,
    : KDL
    :


    What you are talking about is sort of related to one of my recent posts. I have some old AOL modification BAS files that do what you are talking about. If you would like to see them, email me and I will send it to you.


    Mark

    EXAMPLES - WILL NOT WORK THERE ARE DECLARES MISSING. THIS IS JUST AN EXAMPLE.

    Declare Function findwindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Declare Function GetWindow Lib "User32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long


    Function FindChatRoom()
    aol% = findwindow("AOL Frame25", vbNullString)
    mdi% = FindChildByClass(aol%, "MDIClient")
    room% = FindChildByClass(mdi%, "AOL Child")
    Stuff% = FindChildByClass(room%, "_AOL_Listbox")
    MoreStuff% = FindChildByClass(room%, "RICHCNTL")
    If Stuff% <> 0 And MoreStuff% <> 0 Then
    FindChatRoom = room%
    Else:
    FindChatRoom = 0
    End If
    End Function

    Function FindChildByClass(parentw, childhand)
    firs% = GetWindow(parentw, 5)
    If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    firs% = GetWindow(parentw, GW_CHILD)
    If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone

    While firs%
    firss% = GetWindow(parentw, 5)
    If UCase(Mid(GetClass(firss%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    firs% = GetWindow(firs%, 2)
    If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    Wend
    FindChildByClass = 0

    bone:
    room% = firs%
    FindChildByClass = room%

    End Function

    Function findchildbytitle(parentw, childhand)
    firs% = GetWindow(parentw, 5)
    If UCase(GetCaption(firs%)) Like UCase(childhand) Then GoTo bone
    firs% = GetWindow(parentw, GW_CHILD)

    While firs%
    firss% = GetWindow(parentw, 5)
    If UCase(GetCaption(firss%)) Like UCase(childhand) & "*" Then GoTo bone
    firs% = GetWindow(firs%, 2)
    If UCase(GetCaption(firs%)) Like UCase(childhand) & "*" Then GoTo bone
    Wend
    findchildbytitle = 0

    bone:
    room% = firs%
    findchildbytitle = room%
    End Function


  • GideonOmegaGideonOmega Member Posts: 617
    : : : Hi all, hope someone can help me or clear it up for me. Currently Im trying to do send keys to notepad. It works completely but I need Notepad to have the focus. Is there any way to get sendkeys to work without focus so I could have my program sending keys to notepad while I browse the net??
    : : :
    : :
    : : Using SendKeys, no. You can try using SendMessage with the WM_KEYDOWN/WM_KEYUP messages. You'll need to get the textbox's handle to do this. I've never used it, but you can EnumWindows to find the window. With notepad, it's fairly simple because it's the only editbox on the form. Either EnumWindows will tell you the type of window or you can use GetWindowClass on every window contained in the notepad window (ID'able by a caption Like "Notepad - *") until you find one whose class is (I think) "edit".
    : :
    : : Hope this helps,
    : : KDL
    : :
    :
    :
    : What you are talking about is sort of related to one of my recent posts. I have some old AOL modification BAS files that do what you are talking about. If you would like to see them, email me and I will send it to you.
    :
    :
    : Mark
    :
    : EXAMPLES - WILL NOT WORK THERE ARE DECLARES MISSING. THIS IS JUST AN EXAMPLE.
    :
    : Declare Function findwindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    :
    : Declare Function GetWindow Lib "User32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
    :
    :
    : Function FindChatRoom()
    : aol% = findwindow("AOL Frame25", vbNullString)
    : mdi% = FindChildByClass(aol%, "MDIClient")
    : room% = FindChildByClass(mdi%, "AOL Child")
    : Stuff% = FindChildByClass(room%, "_AOL_Listbox")
    : MoreStuff% = FindChildByClass(room%, "RICHCNTL")
    : If Stuff% <> 0 And MoreStuff% <> 0 Then
    : FindChatRoom = room%
    : Else:
    : FindChatRoom = 0
    : End If
    : End Function
    :
    : Function FindChildByClass(parentw, childhand)
    : firs% = GetWindow(parentw, 5)
    : If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    : firs% = GetWindow(parentw, GW_CHILD)
    : If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    :
    : While firs%
    : firss% = GetWindow(parentw, 5)
    : If UCase(Mid(GetClass(firss%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    : firs% = GetWindow(firs%, 2)
    : If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then GoTo bone
    : Wend
    : FindChildByClass = 0
    :
    : bone:
    : room% = firs%
    : FindChildByClass = room%
    :
    : End Function
    :
    : Function findchildbytitle(parentw, childhand)
    : firs% = GetWindow(parentw, 5)
    : If UCase(GetCaption(firs%)) Like UCase(childhand) Then GoTo bone
    : firs% = GetWindow(parentw, GW_CHILD)
    :
    : While firs%
    : firss% = GetWindow(parentw, 5)
    : If UCase(GetCaption(firss%)) Like UCase(childhand) & "*" Then GoTo bone
    : firs% = GetWindow(firs%, 2)
    : If UCase(GetCaption(firs%)) Like UCase(childhand) & "*" Then GoTo bone
    : Wend
    : findchildbytitle = 0
    :
    : bone:
    : room% = firs%
    : findchildbytitle = room%
    : End Function
    :
    :
    :


    Not sure exactly what you are doing for a program, but you could open the notepad in a shell, then send keys to it, then you can use the app.activate command to switch between your shells, here is an example of a shell command:
    [code]
    dim retVal
    retVal = Shell("this_is_the_path_to_exe",vbnormalfocus)
    [/code]
    will open the exe stated in the path, and I belive you can then use
    app.activate with the name you set to = your shell to activate that piticular shell.

    Hope this helps
    [blue]
    C:Dos
    C:Dos Run
    Run Dos Run
    [/blue]

Sign In or Register to comment.