Results 1 to 3 of 3

Thread: Simulate mouse click in external window without activate it

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    460

    Simulate mouse click in external window without activate it

    With this code:

    Code:
    Private Sub Press(MyTableHwnd As IntPtr, X As Integer, Y As Integer)
        Dim lParam As IntPtr = MakeLong(X, Y)
        NativeMethods.SendMessage(MyTableHwnd, WM_MOUSEMOVE, IntPtr.Zero, lParam)
        NativeMethods.SendMessage(MyTableHwnd, WM_LBUTTONDOWN, IntPtr.Zero, lParam)
        Sleep(50)
        NativeMethods.SendMessage(MyTableHwnd, WM_MOUSEMOVE, IntPtr.Zero, lParam)
        NativeMethods.SendMessage(MyTableHwnd, WM_LBUTTONUP, IntPtr.Zero, lParam)
    End Sub
    
    Private Shared Function MakeLong(X As Integer, Y As Integer) As IntPtr
        Return CType((Y << 16) Or (X And &HFFFF), IntPtr)
    End Function
    I can press without problems "drawn" buttons (the only available handle is that of the whole window) painted at X, Y coordinates of some esternal windows. The problem is that, may be depending from the code of the windows, after the click some external windows rest in background (buttons are clicked even if nor visible, under other windows), that's my goal, while other windows jump in the foreground, activated.

    NOTE: other windows jump in the foreground even if I comment the two WM_MOUSEMOVE rows... and in this case the buttons are not pressed unless I don't manually move the mouse cursor over them. So I need the whole code.

    Now the question: some ideas about how to modify my above code to avoid the activation and foreground of all the windows, or may be another different working code?
    Last edited by phil2000; Feb 11th, 2025 at 02:25 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,745

    Re: Simulate mouse click in external window without activate it

    Tell us a bit more about the scenario. You don't want that second program to be activated, but do you need it to be visible? Is the second program your own, or something else?

    I ask the second question just to be sure, because you are probably only trying to automate something in this fashion if you don't have the source code for it, but it would best to be sure.

    As for the first question, a few things to try do come to mind if you don't want that second program to be visible. If you need it to remain visible, then...well, things like moving it off screen won't work.

    Also, what is it about it becoming active that is a problem? There are some options that are ruled out depending on how you answer that question, as well.
    My usual boring signature: Nothing

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,941

    Re: Simulate mouse click in external window without activate it

    @phil2000 Are you still working on your casino automation app? Your question is a little dubious. Are you aware of the rules of this forum?

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