MacroRecoderCsScript
MacroRecoderCsScript copied to clipboard
How to make it play forever?
it is working but there is no option to loop???
surprisingly it compiled in visual studio
made the loop forever haha working now :)
i can't understand why someone makes a working macro recorder but do not add some delay loop options
while (true)
{
if (!File.Exists(scriptPath))
{
ErrorMessage = "[File Error]" + Environment.NewLine + "'" + scriptPath + "' is not found.";
return;
}
ErrorMessage = "";
try
{
buttonState.IsPlaying = true;
cancelTokenSrc = new CancellationTokenSource();
AppEnvironment.GetInstance().CancelToken = cancelTokenSrc.Token;
WinDispacher?.Invoke(new Action(CommandManager.InvalidateRequerySuggested));
await ScriptExecuter.ExecuteAsync(ScriptPath);
}
catch (CompilationErrorException ex)
{
ErrorMessage = "[Compile Error]" + Environment.NewLine + ex.Message;
}
catch (TaskCanceledException)
{
ErrorMessage = "[Message]Script was cancelled.";
}
catch (Exception)
{
throw;
}
buttonState.IsPlaying = false;
WinDispacher?.Invoke(new Action(CommandManager.InvalidateRequerySuggested));
}
A "forever loop mode" is not necessary to be coded into the MacroRecorder itself IMO since we use CSharp Script This can be achieved without modifying the source. You could just do something like this:
// main.csx
#load "C:\\Users\\<user>\\Documents\\someTask.csx"
using System;
using System.Threading.Tasks;
int delay = 1000 * 60 * 2;
// Add some jitter to the click position
Random _random = new Random();
int Jitter(int originalValue)
{
int jitter = _random.Next(-10, 11);
int jitteredValue = originalValue + jitter;
return jitteredValue;
}
async Task DoClick(int a, int b) {
int jA = Jitter(a);
int jB = Jitter(b);
await SetMousePos(jA, jB);
await PushLeftButton(jA, jB);
await Delay(Jitter(100));
await PullLeftButton(jA, jB);
}
while(true) {
await executeSomeTask();
await Delay(delay);
}
// someTask.csx
public async void someTask() {
// Your recorded macro
// Replace PushLeft/PullLeft with DoClick()
DoClick(444, 444);
}