diff --git a/.gitignore b/.gitignore
index ca4b4ed..b7b7df9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,3 +62,4 @@ packages/
#Test files
*.testsettings
+.vs/
diff --git a/WindowsInput.Tests/InputSimulatorExamples.cs b/WindowsInput.Tests/InputSimulatorExamples.cs
index d46fcd8..659a2e0 100644
--- a/WindowsInput.Tests/InputSimulatorExamples.cs
+++ b/WindowsInput.Tests/InputSimulatorExamples.cs
@@ -1,4 +1,9 @@
using NUnit.Framework;
+using System;
+using System.Diagnostics;
+using System.Drawing;
+using System.IO;
+using System.Windows.Forms;
using WindowsInput.Native;
namespace WindowsInput.Tests
@@ -70,13 +75,70 @@ public void AnotherTest()
[Explicit]
public void TestMouseMoveTo()
{
+ var bounds = Screen.PrimaryScreen.WorkingArea;
+
var sim = new InputSimulator();
sim.Mouse
.MoveMouseTo(0, 0)
.Sleep(1000)
- .MoveMouseTo(65535, 65535)
+ .MoveMouseTo(bounds.Width, bounds.Height)
.Sleep(1000)
- .MoveMouseTo(65535/2, 65535/2);
+ .MoveMouseTo(bounds.Width / 2, bounds.Height / 2);
+ }
+
+ [Test]
+ [Explicit]
+ public void TestDragDrop()
+ {
+ Process notepad = Process.Start(Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "notepad.exe"));
+ notepad.WaitForInputIdle();
+
+ var sim = new InputSimulator();
+
+ var bounds = WaitForMainWindowPosition(notepad, sim);
+ Assert.IsFalse(bounds.IsEmpty, "Window is not showing up");
+
+ // get grab position in the title bar.
+ int x = bounds.Left + (bounds.Width / 2);
+ int y = bounds.Top + 10;
+
+ sim.Mouse
+ .MoveMouseTo(x, y)
+ .Sleep(100)
+ .LeftButtonDown();
+
+ for (int i = 0; i < 100; i += 1)
+ {
+ sim.Mouse.MoveMouseTo(x + i, y).Sleep(1);
+ }
+
+ sim.Mouse.LeftButtonUp();
+
+ notepad.Kill();
+ }
+
+ private Rectangle WaitForMainWindowPosition(Process process, InputSimulator sim, int timeoutMilliseconds = 5000)
+ {
+ int delay = 10;
+ for (int timeout = 0; timeout < timeoutMilliseconds; timeout += delay)
+ {
+ NativeMethods.WINDOWPLACEMENT placement = new NativeMethods.WINDOWPLACEMENT();
+ NativeMethods.GetWindowPlacement(process.MainWindowHandle, ref placement);
+ var width = (placement.rcNormalPosition.right - placement.rcNormalPosition.left);
+ if (width == 0)
+ {
+ sim.Mouse.Sleep(delay);
+ }
+ else
+ {
+ // find a position in the center of the title bar.
+ var height = (placement.rcNormalPosition.right - placement.rcNormalPosition.left);
+ var x = placement.rcNormalPosition.left;
+ var y = placement.rcNormalPosition.top;
+ return new Rectangle((int)x, (int)y, (int)width, (int)height);
+ }
+ }
+ return Rectangle.Empty;
}
}
}
\ No newline at end of file
diff --git a/WindowsInput.Tests/NativeMethods/NativeMethods.cs b/WindowsInput.Tests/NativeMethods/NativeMethods.cs
new file mode 100644
index 0000000..79bbb4d
--- /dev/null
+++ b/WindowsInput.Tests/NativeMethods/NativeMethods.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsInput.Tests
+{
+ internal class NativeMethods
+ {
+ [StructLayout(LayoutKind.Sequential)]
+ public struct POINT
+ {
+ int x;
+ public int y;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RECT
+ {
+ public int left;
+ public int top;
+ public int right;
+ public int bottom;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct WINDOWPLACEMENT
+ {
+ public UInt32 length;
+ public UInt32 flags;
+ public UInt32 showCmd;
+ public POINT ptMinPosition;
+ public POINT ptMaxPosition;
+ public RECT rcNormalPosition;
+ public RECT rcDevice;
+ }
+ ;
+ ///
+ /// Retrieves the show state and the restored, minimized, and maximized positions of the specified window.
+ ///
+ ///
+ ///
+ ///
+ ///
+ [DllImport("user32.dll")]
+ public static extern bool GetWindowPlacement(IntPtr hwnd, ref WINDOWPLACEMENT placement);
+ }
+}
diff --git a/WindowsInput.Tests/WindowsInput.Tests.csproj b/WindowsInput.Tests/WindowsInput.Tests.csproj
index 0c66b34..e82ae79 100644
--- a/WindowsInput.Tests/WindowsInput.Tests.csproj
+++ b/WindowsInput.Tests/WindowsInput.Tests.csproj
@@ -1,5 +1,7 @@
-
+
+
+
Debug
AnyCPU
@@ -10,11 +12,13 @@
Properties
WindowsInput.Tests
WindowsInput.Tests
- v4.5
+ v4.8
512
..\
true
+
+
true
@@ -45,8 +49,8 @@
..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll
-
- ..\packages\NUnit.2.6.2\lib\nunit.framework.dll
+
+ ..\packages\NUnit.3.13.3\lib\net45\nunit.framework.dll
@@ -60,6 +64,7 @@
+
@@ -87,6 +92,13 @@
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+