[vb2010] MouseEvents don's works until EndSub?-VBForums
Results 1 to 3 of 3

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

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    238

    [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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,800

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    238

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.