Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asking very basic command
#7
its normal ? for pause and quit  script this long ? i made it with help chatgpt and finaly works T_T
 
Code:
Copy      Help
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
        }
    }
}


Messages In This Thread
Asking very basic command - by Rudeyz - 11-01-2024, 10:26 PM
RE: Asking very basic command - by Rudeyz - 11-04-2024, 05:59 AM
RE: Asking very basic command - by Gintaras - 11-04-2024, 08:06 AM
RE: Asking very basic command - by Rudeyz - 11-11-2024, 06:47 AM
RE: Asking very basic command - by Gintaras - 11-11-2024, 07:29 AM
RE: Asking very basic command - by Rudeyz - 11-15-2024, 09:31 AM
RE: Asking very basic command - by Rudeyz - 12-11-2024, 09:28 AM
RE: Asking very basic command - by Gintaras - 12-11-2024, 10:07 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)