Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse hover simulation, and ability to not restart UWP apps when connecting. #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/WinAppDriver/Handlers/NewSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ public object Handle(Dictionary<string, string> 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
Expand Down
5 changes: 4 additions & 1 deletion src/WinAppDriver/ResetStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ internal enum ResetStrategy
Full,

[EnumMember(Value = "noReset")]
No
No,

[EnumMember(Value = "skipActivate")]
SkipActivate
}
}
40 changes: 38 additions & 2 deletions src/WinAppDriver/UI/Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

internal class Mouse : IMouse
{
private const int NormalizedMaximum = 0xFFFF;

private static ILogger logger = Logger.GetLogger("WinAppDriver");

private IWinUserWrap winUser;
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/WinAppDriver/Wrappers/WinUserWrapper/IWinUserWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal enum MOUSEEVENTF : uint
MIDDLEDOWN = 0x0020,
MIDDLEUP = 0x0040,
ABSOLUTE = 0x8000,
VIRTUALDESK = 0x4000
}

[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")]
Expand Down