diff --git a/src/WinAppDriver/Handlers/NewSessionHandler.cs b/src/WinAppDriver/Handlers/NewSessionHandler.cs index 1e06f24..c94833a 100755 --- a/src/WinAppDriver/Handlers/NewSessionHandler.cs +++ b/src/WinAppDriver/Handlers/NewSessionHandler.cs @@ -156,7 +156,11 @@ public object Handle(Dictionary urlParams, string body, ref ISes } } + if (caps.ResetStrategy != ResetStrategy.SkipActivate) + { app.Activate(); + } + session = this.sessionManager.CreateSession(app, caps); // TODO turn off IME, release all modifier keys diff --git a/src/WinAppDriver/ResetStrategy.cs b/src/WinAppDriver/ResetStrategy.cs index 81b4f72..8b632f1 100755 --- a/src/WinAppDriver/ResetStrategy.cs +++ b/src/WinAppDriver/ResetStrategy.cs @@ -14,6 +14,9 @@ internal enum ResetStrategy Full, [EnumMember(Value = "noReset")] - No + No, + + [EnumMember(Value = "skipActivate")] + SkipActivate } } \ No newline at end of file diff --git a/src/WinAppDriver/UI/Mouse.cs b/src/WinAppDriver/UI/Mouse.cs index e3eb281..962c422 100755 --- a/src/WinAppDriver/UI/Mouse.cs +++ b/src/WinAppDriver/UI/Mouse.cs @@ -10,6 +10,8 @@ internal class Mouse : IMouse { + private const int NormalizedMaximum = 0xFFFF; + private static ILogger logger = Logger.GetLogger("WinAppDriver"); private IWinUserWrap winUser; @@ -21,8 +23,42 @@ public Mouse(IWinUserWrap winUser) public Point Position { - get { return System.Windows.Forms.Cursor.Position; } - private set { System.Windows.Forms.Cursor.Position = value; } + get + { + return System.Windows.Forms.Cursor.Position; + } + + private set + { + Point normalizedXY = this.NormalizeCoordinates(value.X, value.Y); + + INPUT input = new INPUT + { + type = (int)INPUTTYPE.MOUSE, + u = new InputUnion + { + mi = new MOUSEINPUT + { + dx = normalizedXY.X, + dy = normalizedXY.Y, + mouseData = 0, + dwFlags = (uint)(MOUSEEVENTF.MOVE | MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.VIRTUALDESK), + time = 0, + dwExtraInfo = new IntPtr(0), + } + } + }; + this.winUser.SendInput(1, new INPUT[] { input }, Marshal.SizeOf(typeof(INPUT))); + } + } + + public Point NormalizeCoordinates(int x, int y) + { + var width = System.Windows.Forms.SystemInformation.VirtualScreen.Width; + var height = System.Windows.Forms.SystemInformation.VirtualScreen.Height; + int normalizedX = (NormalizedMaximum * x) / width; + int normalizedY = (NormalizedMaximum * y) / height; + return new Point(normalizedX, normalizedY); } public void Click(MouseButton button) diff --git a/src/WinAppDriver/Wrappers/WinUserWrapper/IWinUserWrap.cs b/src/WinAppDriver/Wrappers/WinUserWrapper/IWinUserWrap.cs index 5ab5e3b..188c8fb 100755 --- a/src/WinAppDriver/Wrappers/WinUserWrapper/IWinUserWrap.cs +++ b/src/WinAppDriver/Wrappers/WinUserWrapper/IWinUserWrap.cs @@ -84,6 +84,7 @@ internal enum MOUSEEVENTF : uint MIDDLEDOWN = 0x0020, MIDDLEUP = 0x0040, ABSOLUTE = 0x8000, + VIRTUALDESK = 0x4000 } [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")]