Results 1 to 3 of 3

Thread: [vb2010] MouseEvents don's works until EndSub?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    459

    [vb2010] MouseEvents don's works until EndSub?

    I want to press a Button of an external application to close it (I MUST press the Button to confirm some changes)

    Code:
       
    some code before.....     
    Cursor.Position = New Point(X,Y)
    NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, IntPtr.Zero)
    NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    'test
    Threading.Thread.Sleep(5000)
    The question is: why if I insert a Sleep(5000) event the button IS NOT pressed until the end of the Sleep event? When I reach the Sleep code the MouseEvent code has already been processed

    How to force anyway the MouseEvent?

    In effect the true code is:

    Code:
    Cursor.Position = New Point(X,Y)
    NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, IntPtr.Zero)
    NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    
    Threading.Thread.Sleep(100)
    'I want to be sure the window is closed...
    If NativeMethods.FindWindow(Nothing, WinHwnd) <> IntPtr.Zero  Then
    
        Cursor.Position = New Point(X,Y)
        NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0,  IntPtr.Zero)
        NativeMethods.Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    But since the MouseEvent don't works until the End of the Sub the second part of the code is ALWAYS processed, and I am not sure that the window will be really closed.

    All the code (that is quite complex) is in a Module, I ca'nt add Timers or Background Workers...
    The more simple way would be to force the MouseEvent BEFORE to exit from the Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [vb2010] MouseEvents don's works until EndSub?

    Given that it's unmanaged code I'm not sure but try a call to Application.DoEvents before Thread.Sleep.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    459

    Re: [vb2010] MouseEvents don's works until EndSub?

    Quote Originally Posted by jmcilhinney View Post
    Given that it's unmanaged code I'm not sure but try a call to Application.DoEvents before Thread.Sleep.
    Tried... nothing changes .... ty anyway

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