12-11-2024, 09:28 AM
its normal ? for pause and quit script this long ? i made it with help chatgpt and finaly works T_T
using System;
using LibreAutomate;
public class Script
{
public static void Main()
{
bool isPaused = false; // Flag to check the pause status
int i = 1;
while (true)
{
// Wait for Ctrl+P to pause or resume
if (keys.isPressed(KKey.Ctrl) && keys.isPressed(KKey.P))
{
if (!isPaused) // If not paused, then pause
{
print.it("Script paused. Press Ctrl+P again to resume.");
isPaused = true; // Set pause status
}
else // If paused, then resume
{
print.it("Resuming script...");
isPaused = false; // Set resume status
}
// Wait until Ctrl+P is released to avoid spam
while (keys.isPressed(KKey.Ctrl) && keys.isPressed(KKey.P))
{
100.ms(); // Wait 100ms
}
}
// Wait for Ctrl+R to restart
if (keys.isPressed(KKey.Ctrl) && keys.isPressed(KKey.R))
{
print.it("Restarting from the beginning...");
i = 1; // Reset the number to 1
// Wait until Ctrl+R is released
while (keys.isPressed(KKey.Ctrl) && keys.isPressed(KKey.R))
{
100.ms(); // Wait 100ms
}
}
// Wait for Ctrl+Q to exit the script
if (keys.isPressed(KKey.Ctrl) && keys.isPressed(KKey.Q))
{
print.it("Exiting the script.");
break; // Exit the loop and stop the script
}
// If not paused, continue printing numbers
if (!isPaused)
{
print.it(i.ToString());
i++;
if (i > 20) i = 1; // Reset the number to 1 after reaching 20
}
500.ms(); // Wait 500ms before continuing
}
}
}