Skip to content

Commit

Permalink
Options update
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaifm committed Nov 8, 2022
1 parent f7ee007 commit ad70e5f
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 207 deletions.
62 changes: 60 additions & 2 deletions ElegantRecorder/AutomationEngine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ElegantRecorder
{
Expand Down Expand Up @@ -69,12 +70,12 @@ public virtual bool ReplayMouseMoveAction(UIAction action, ref string status)
return true;
}

public virtual bool ReplayMousePathAction(UIAction action, ref string status)
public virtual bool ReplayMousePathAction(UIAction action, string playbackSpeed, ref string status)
{
foreach(var m in action.MoveData)
{
App.WinAPI.MouseMove(m.X, m.Y, UIntPtr.Zero);
Thread.Sleep((int)App.ElegantOptions.GetPlaybackSpeedDuration(m.T));
Thread.Sleep((int)ElegantOptions.GetPlaybackSpeedDuration(playbackSpeed, m.T));
}

return true;
Expand All @@ -97,5 +98,62 @@ public virtual bool ReplayClipboardAction(UIAction action, ref string status)
App.WinAPI.SetClipboardText(action.TextData);
return true;
}

public void CleanResidualKeys()
{
//prevent keys remaining pressed at the end of the recording

for (int i = App.UISteps.Count - 1; i >= 0; i--)
{
if (App.UISteps[i].EventType == "keypress")
{
if (App.WinAPI.isKeyUp((int)App.UISteps[i].Flags))
break;
else
App.UISteps.RemoveAt(i);
}
else
{
break;
}
}
}

public void CompressMoveData()
{
List<MoveData> moveData = new List<MoveData>();
string status = "";

for (int i = App.UISteps.Count - 1; i >= 0; i--)
{
if (App.UISteps[i].EventType == "mousemove")
{
moveData.Insert(0, new MoveData { X = (int)App.UISteps[i].OffsetX, Y = (int)App.UISteps[i].OffsetY, T = (int)App.UISteps[i].elapsed });
App.UISteps.RemoveAt(i);
}
else
{
if (moveData.Count != 0)
{
var uiAction = new UIAction();
FillMousePathAction(ref uiAction, ref status, moveData);

App.UISteps.Insert(i + 1, uiAction);

moveData.Clear();
}
}
}

if (moveData.Count != 0)
{
var uiAction = new UIAction();
FillMousePathAction(ref uiAction, ref status, moveData);

App.UISteps.Insert(0, uiAction);

moveData.Clear();
}
}
}
}
17 changes: 12 additions & 5 deletions ElegantRecorder/ElegantOptions.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ElegantRecorder
{
public class ElegantOptions
{
public static int DefaultFormHeight = 127;

public string PlaybackSpeed { get; set; }
public int RecordHotkey { get; set; }
public int StopHotkey { get; set; }
public bool RecordMouseMove { get; set; }
public bool RecordClipboard { get; set; }
public bool RestrictToExe { get; set; }
public string ExePath { get; set; }
public string AutomationEngine { get; set; }
public string DataFolder { get; set; }
public bool ExpandedUI { get; set; }
public int FormHeight { get; set; }
public int DataGridHeight { get; set; }

[JsonIgnore]
public string PlaybackSpeed { get; set; }
[JsonIgnore]
public bool RestrictToExe { get; set; }
[JsonIgnore]
public string ExePath { get; set; }

public ElegantOptions()
{
//default options

PlaybackSpeed = "Normal";
RecordHotkey = 0;
StopHotkey = 0;
Expand All @@ -41,9 +48,9 @@ public void Save(string FilePath)
File.WriteAllText(FilePath, JsonSerializer.Serialize(this));
}

public double GetPlaybackSpeedDuration(double initialDuration)
public static double GetPlaybackSpeedDuration(string playbackSpeed, double initialDuration)
{
switch(PlaybackSpeed)
switch(playbackSpeed)
{
case "Fastest":
return 0;
Expand Down
Loading

0 comments on commit ad70e5f

Please sign in to comment.