Results 1 to 16 of 16

Thread: [RESOLVED] Release Sendkeys to Edit my Application

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Resolved [RESOLVED] Release Sendkeys to Edit my Application

    Okay.

    I have an application that I send keys (strings ) to, say Notepad.
    It send a string to the last focus app. other than mine
    All works fine

    However, If I want to edit a text box on my application it still keeps sending key strings to notepad.

    How do I release the current window that my app is talking too so I can edit my Textbox1.Text??

    Code to capture window api.

    Code:
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
    Code:
    Shared Function ReleaseCapture() As Boolean
    
     >>>> WHAT GOES HERE so I can edit Textbox1 when it has focus??
    
    End Function
    Thanks in advanced.
    Last edited by pixelink; Jun 20th, 2022 at 12:20 PM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Release Sendkeys to Edit my Application

    Where/how are you calling the SendMessage method?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Code:
    SendKeys.Send("^(v)")
    I have an on screen keyboard.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Release Sendkeys to Edit my Application

    Right. And where are you calling that from?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Butons or clicking on a listbox item
    Last edited by pixelink; Jun 20th, 2022 at 04:08 PM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Like I said. The Sendkeys and communicating with other apps works great.
    Its just trying to edit a Textbox on my own app after a link is established.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Release Sendkeys to Edit my Application

    That's fine. I wanted to rule out you calling this method in a timer or in a separate thread.

    Looking at the documentation on the particular API I don't see anything that would hold the command. So at this point, it is a bit out of my wheelhouse. I'll let someone else chime in to see if they have experienced this issue.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    I do notice if I do a refresh on my listbox or change a value in a dropdown, the link is broke and then I can edit my own textbox.
    Or I can close the app and restart it. That breaks the link too.

    But, is there a way to just set the main form and break the message link between my app and another easily?
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Release Sendkeys to Edit my Application

    Edit: never mind, updates were made to the thread that made my post irrelevant.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    I wonder, how do I make a call to re-paint the form. I wonder if that will work because it seems that picking an item from a dropdown combo box works.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Well, guess not.

    Code:
    Me.Invalidate()
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Hmm... I just put a button on the form and displayed a Messagebox. That breaks the link.
    So, how can I invoke something that I don't have to respond to or click, i.e. like a dropdown combo box?
    Last edited by pixelink; Jun 20th, 2022 at 03:37 PM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    So, the more I try different ways to refresh the form.
    It seems that mouse interaction is required with a message box, my own modal form or a dropdown box.

    There has to be a better way to break the link to other apps from my own form.
    Last edited by pixelink; Jun 21st, 2022 at 02:00 PM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Still looking for a solution
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    Still looking for a solution to this issue.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Apr 2019
    Location
    Sabattus
    Posts
    234

    Re: Release Sendkeys to Edit my Application

    I figured it out.

    I had to force my app which was already in the foreground (and topmost)
    to be the actual foreground app that has focus.

    Even though I would click inside the Textbox, because Notepad was the actual foreground app in the thread,
    I had to force it to be the foreground in the thread.


    Code:
    'setforegroundowindow
        Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
        Public Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
        Public Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Integer) As Boolean
        Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    
        Public Const SW_RESTORE As Integer = 9
        Public Const SW_SHOW As Integer = 5
    
        'setforegroundowindow
        Sub FocusWindow(ByVal strWindowCaption As String, ByVal strClassName As String)
            Dim hWnd As Integer
            hWnd = FindWindow(strClassName, strWindowCaption)
    
            If hWnd > 0 Then
                SetForegroundWindow(hWnd)
    
                If IsIconic(hWnd) Then  'Restore if minimized
                    ShowWindow(hWnd, SW_RESTORE)
                Else
                    ShowWindow(hWnd, SW_SHOW)
                End If
            End If
        End Sub

    Code:
    Private Sub txtEditor_Enter(sender As Object, e As EventArgs) Handles txtEditor.Enter
    
            'setforegroundowindow to my app
            FocusWindow("Desktop Tasks", Nothing)
    
        End Sub
    Last edited by pixelink; Jun 21st, 2022 at 05:05 PM.
    Can't Type - Forgetful - Had Stroke = Forgive this old man!
    Website: https://pixelinkmedia.wixsite.com/frankhilton
    VSCOMM 2022 • LAZARUS 2.2.0 • Win10 • 16G RAM • Nvida GForce RTX 2060

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