Skip to content

Commit

Permalink
Updated replay logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaifm committed Sep 23, 2022
1 parent 1af34ce commit 578b4fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions ElegantRecorder.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions ElegantRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,26 +633,28 @@ private void buttonReplay_Click(object sender, EventArgs e)
return;
}

Rect windowRect = (Rect)topLevelWindow.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

var x = (int)windowRect.X + action.OffsetX;
var y = (int)windowRect.Y + action.OffsetY;

AutomationElement targetElement = FindElementInWindow(action.ControlName, action.AutomationId, action.ControlType, topLevelWindow, action.Level, action.ChildIndex);

if (targetElement == null)
{
labelStatus.Text = "Failed to find element: " + action.ControlName;
return;
}

Rect windowRect = (Rect)topLevelWindow.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
Rect elementRect = (Rect)targetElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

var x = (int)windowRect.X + action.OffsetX;
var y = (int)windowRect.Y + action.OffsetY;

if (elementRect.X > x || x > elementRect.X + elementRect.Width ||
elementRect.Y > y || y > elementRect.Y + elementRect.Height)
else
{
var point = targetElement.GetClickablePoint();
x = (int)point.X;
y = (int)point.Y;
Rect elementRect = (Rect)targetElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

if (elementRect.X > x || x > elementRect.X + elementRect.Width ||
elementRect.Y > y || y > elementRect.Y + elementRect.Height)
{
var point = targetElement.GetClickablePoint();
x = (int)point.X;
y = (int)point.Y;
}
}

int dx = (int)x * 65535 / screenBounds.Width + 1;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Elegant Recorder

![image](https://user-images.githubusercontent.com/981184/191825392-c3e051b0-e24a-4bc9-a23d-a2b984517861.png)
![image](https://user-images.githubusercontent.com/981184/191975186-e6527de6-3ff1-4c46-b0a1-ed4cde394ca0.png)

Experimental tool that allows you to record and replay your actions inside Windows applications.

Expand Down

0 comments on commit 578b4fc

Please sign in to comment.