Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asking very basic command
#1
  • "Hi, I'm trying to learn about C#, and I have no basic knowledge about coding. I am using ChatGPT as a helper, and sorry for my broken English.
I am trying to make a basic script to run continuously with start, pause, and stop, and to move to points 1, 2, 3, 4, and 5, but somehow I am already stuck and can't open Notepad.
The code is like this.

 
Code:
Copy      Help
// Clears the console for a fresh display of results
print.clear();

// Grouping mouse click coordinates
// Mouse coordinates in (x, y) format
var points = new[] {
    (47, 845), // Point 1
    (136, 845), // Point 2
    (221, 845), // Point 3
    (48, 784), // Point 4
    (137, 784)  // Point 5
};

// Function to open Notepad if it is not active
void OpenNotepad() {
    var w = wnd.find(1, "*- Notepad", "Notepad");
    
    if (w == null) {
        // If Notepad is not found, open it and wait for it to be ready
        run.it(@"C:\test folder\ThisLA.txt"); // Open file in the test folder
        w = wait.until(2, () => wnd.find(1, "*- Notepad", "Notepad")); // Wait until Notepad opens

        if (w == null) {
            print.it("Error: Notepad window not found."); // Display error message if Notepad still not found
            return; // Exit function if Notepad could not be found
        }
    }
    
    w.Activate(); // Activate if already open
}

// Macro HeloA
void HeloA() {
    OpenNotepad();
    var w = wnd.find(1, "*- Notepad", "Notepad");

    if (w == null) {
        print.it("Failed to run HeloA: Notepad is not open.");
        return;
    }

    // Click on points 1, 3, and 5
    for (int i = 0; i < points.Length; i += 2) {
        mouse.move(points[i].Item1, points[i].Item2); // Move mouse to specified point
        mouse.click(); // Left-click the mouse
        500.ms(); // Wait 500 ms
    }

    // Type text into Notepad
    keys.sendt("Hello, this is script HeloA. Have a nice day!");
}

// Macro HeloB
void HeloB() {
    OpenNotepad();
    var w = wnd.find(1, "*- Notepad", "Notepad");

    if (w == null) {
        print.it("Failed to run HeloB: Notepad is not open.");
        return;
    }

    // Click on points 2, 4, and 6
    for (int i = 1; i < points.Length; i += 2) {
        mouse.move(points[i].Item1, points[i].Item2);
        mouse.click();
        500.ms();
    }

    // Type text into Notepad
    keys.sendt("Hello, this is script HeloB. Have a great day!");
}

// Run the main script
HeloA(); // Call Macro HeloA
HeloB(); // Call Macro HeloB

--- and itsaid eror cant open notepad

And I want each script to have its own void so I can run or test each code. Should I make it like a script or a class?"


Code:
Copy      Help
https://prnt.sc/tHZwIxifhCuC


And thank you
#2
Code:
Copy      Help
using System;
using Au;

public class Program {
    public static void Main() {
        HeloA.Function1(); // Calling HeloA
    }
}
Code:
Copy      Help
using Au;

public class HeloA {
    
    public static void Function1() {
        using (opt.scope.all()) { //recorded
            opt.mouse.MoveSpeed = opt.key.KeySpeed = opt.key.TextSpeed = 10;
            var w1 = wnd.find(0, "Untitled - Notepad", "Notepad").Activate();
            var c1 = w1.Child(1, id: 15); // Edit "Text Editor"
            keys.send("^Helo This is Macro class A");
        }
        
        
    }
    
    
}


test HeloA.cs(6,3): error CS0103: The name 'HeloA' does not exist in the current context

yeah ... ---
https://prnt.sc/dpkU8f9gn641
#3
#1
ChatGPT usually can't generate valid C# code that uses LibreAutomate functions. It isn't familiar enough with LibreAutomate. Use ChatGPT only to generate code without LibreAutomate functions.
 


#2
The easiest way to make it work, rename folder "Notepad" to "@Notepad". Then all files in that folder can use classes defined anywhere in that folder. And let "testA-" be the first file in that folder.
More info in Cookbook article "Multi-file scripts, projects".
#4
#2 can you screenshot how ?


Im to dumb ? i read on cookbook but still didnt understand, only understand use recording tools .

https://www.libreautomate.com/cookbook/r...jump).html
https://www.libreautomate.com/cookbook/f...rate).html
I saw it but where and how i should add into

There is any one make video about Liberate?
#5
I see in your screenshot the script file and file HeloA are in folder Notepad. Right-click the Notepad folder and select Rename. Make it @Notepad.

You can find many tutorials and videos about C# statements return, for etc on the internet. They are not specific to LibreAutomate.
#6
Little by little, I am getting used to it. As for why my trigger isn’t working, it’s because I’m still making the script in the editor. I need to either make it into an exe or press start in the editor first for the macro/script to run, right?

https://prnt.sc/1g--2epoGtEx

for infinity loop
 
Code:
Copy      Help
for (;;) { //repeat forever or until break/return/goto/throw
    500.ms(); //wait 500 ms
    print.it(1);
    if (keys.isCtrl) break; //exit the for block
    if (keys.isShift) continue; //skip remaining statements
    print.it(2);
}

for (int i = 0, j = 0; i < 5 && !keys.isShift; i++, j+=10) {
    print.it(i, j);
    500.ms();
}


i found in cook book inside the editor not from website .
#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
        }
    }
}
#8
No. ChatGPT does not know it. Look in Cookbook.

example
Code:
Copy      Help
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop, pauseKey: KKey.MediaPlayPause);

for (int i = 0; i < 100; i++) {
    script.pause();
    print.it(i);
    500.ms();
}


Forum Jump:


Users browsing this thread: 3 Guest(s)