From cadd5226dce3dd8df0417872deee9b66f59bf5d4 Mon Sep 17 00:00:00 2001 From: Sam Bent Date: Tue, 25 Jun 2019 11:12:01 -0700 Subject: [PATCH] Port test changes from .NET 4.8 --- .../test/Common/DRT/TestServices/DrtBaseInput.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/test/Common/DRT/TestServices/DrtBaseInput.cs b/src/Microsoft.DotNet.Wpf/test/Common/DRT/TestServices/DrtBaseInput.cs index 5f9304c70a8..85a54108f6a 100644 --- a/src/Microsoft.DotNet.Wpf/test/Common/DRT/TestServices/DrtBaseInput.cs +++ b/src/Microsoft.DotNet.Wpf/test/Common/DRT/TestServices/DrtBaseInput.cs @@ -371,6 +371,7 @@ internal class InternalNativeMethods public const int KEYEVENTF_UNICODE = 0x0004; public const int KEYEVENTF_SCANCODE = 0x0008; + public const int MOUSEEVENTF_MOVE_NOCOALESCE = 0x2000; public const int MOUSEEVENTF_VIRTUALDESK = 0x4000; public const int INPUT_MOUSE = 0; @@ -483,6 +484,12 @@ public static void SendMouseInput( double x, double y, int data, SendMouseInputF intflags |= InternalNativeMethods.MOUSEEVENTF_VIRTUALDESK; } + + // don't coalesce mouse moves - tests expect to see the results immediately + if ((intflags & (int)SendMouseInputFlags.Move) != 0) + { + intflags |= InternalNativeMethods.MOUSEEVENTF_MOVE_NOCOALESCE; + } InternalUnsafeNativeMethods.INPUT mi = new InternalUnsafeNativeMethods.INPUT(); mi.type = InternalNativeMethods.INPUT_MOUSE; @@ -495,6 +502,14 @@ public static void SendMouseInput( double x, double y, int data, SendMouseInputF //Console.WriteLine("Sending"); if ( InternalUnsafeNativeMethods.SendInput( 1, ref mi, Marshal.SizeOf( mi ) ) == 0 ) throw new Win32Exception( Marshal.GetLastWin32Error() ); + + if ((intflags & (int)SendMouseInputFlags.Wheel) != 0) + { + // MouseWheel input seems to be getting coalesced by the OS, similar to mouse-move. + // There isn't a NOCOALESCE flag to turn this off, so instead just sleep for + // a short time, hopefully enough to avoid the coalescing. + System.Threading.Thread.Sleep(50); + } }